1

Please anyone can help to draw this curve(shown in the picture) with two different line style with the help of tikzpicture? Thanks in advance I want to draw curve as shown in the image

\documentclass[tikz, border=1cm]{standalone} \usetikzlibrary{arrows.meta, ext.topaths.arcthrough, decorations.markings} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{amsmath} \usepackage{tikz} \usepackage{tikz-3dplot} \begin{document} \begin{tikzpicture}[xscale=2.2, yscale=1.2] % Increase x-axis and decrease y-axis scales % Define the function (centered on the y-axis) \def\func{-(\x)^2 +4} % Parabola opening downwards, vertex at (0, 6) % Define the bounds for the x-values \def\lowerbound{-2.5} \def\upperbound{2.5} % Draw the axes \draw[->] (-3,0) -- (3,0) node[right] {$x$}; \draw[->] (0,-1) -- (0,7) node[above] {$y$}; % Add ticks on the x-axis \foreach \x in {-2,-1,0,1,2,3} { \draw (\x,0.15) -- (\x,-0.15); % tick marks } % Add ticks on the y-axis \foreach \y in {-1,0,1,2,3,4,5} { \draw (0.15,\y) -- (-0.15,\y); % tick marks } % Draw the function (parabola centered on the y-axis) \draw[domain=\lowerbound:\upperbound,smooth,variable=\x,line width=0.5mm] plot ({\x},{-(\x)^2 + 6}); \end{tikzpicture} \end{document} 
3
  • 1
    Perceive various segments as sin, cosine or parabola, which Tikz can draw. Change line options as needed Commented Sep 6, 2024 at 7:33
  • 2
    can't you just plot 3 times with different domains? Commented Sep 6, 2024 at 15:18
  • @cfr I did it right now after very hard work. Thank you Commented Sep 6, 2024 at 17:05

1 Answer 1

3

In my opinion you need to describe your disered curve mathematically.

Since I do not know, which function that exactly is, I thought about something like -sin(x) along the y-axis, which has an ampiltude of inv(-x² + 6) = +/- sqrt(6-x); with other words:

% inv(-x² + 6) = +/- sqrt(6-x) ---> "amplitude function" % max(-x² + 6) = 6 \tikzset{trig format=rad} \draw[domain=0:6, smooth, red!55, line width=1mm, ] plot ({sqrt(6-\x)*(-sin(\x))},{\x}); 

This gives you a workaround for which you can adjust the finer details of your curve yourself.

And: as already mentioned in the comments, you can work domain-wise to set different line styles (dashed, dotted,...)

enter image description here

\documentclass[tikz, border=1cm]{standalone} \usetikzlibrary{arrows.meta, ext.topaths.arcthrough, decorations.markings} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{amsmath} \usepackage{tikz} \usepackage{tikz-3dplot} \begin{document} \begin{tikzpicture}[xscale=2.2, yscale=1.2] % Increase x-axis and decrease y-axis scales % Define the function (centered on the y-axis) \def\func{-(\x)^2 +4} % Parabola opening downwards, vertex at (0, 6) % Define the bounds for the x-values \def\lowerbound{-2.5} \def\upperbound{2.5} % Draw the axes \draw[->] (-3,0) -- (3,0) node[right] {$x$}; \draw[->] (0,-1) -- (0,7) node[above] {$y$}; % Add ticks on the x-axis \foreach \x in {-2,-1,0,1,2,3} { \draw (\x,0.15) -- (\x,-0.15); % tick marks } % Add ticks on the y-axis \foreach \y in {-1,0,1,2,3,4,5} { \draw (0.15,\y) -- (-0.15,\y); % tick marks } % Draw the function (parabola centered on the y-axis) \draw[domain=\lowerbound:\upperbound,smooth,variable=\x,line width=0.5mm] plot ({\x},{-(\x)^2 + 6}); % inv(-x² + 6) = +/- sqrt(6-x) ---> "amplitude function" % max(-x² + 6) = 6 \tikzset{trig format=rad} \draw[domain=0:6, smooth, red!55, line width=1mm, ] plot ({sqrt(6-\x)*(-sin(\x))},{\x}); \draw[domain=0:2, smooth, very thick, ] plot ({sqrt(6-\x)*(-sin(\x))},{\x}); \draw[domain=2:4, smooth, thick, dashed, ] plot ({sqrt(6-\x)*(-sin(\x))},{\x}); \draw[domain=4:6, smooth, thick, dotted, ] plot ({sqrt(6-\x)*(-sin(\x))},{\x}); \end{tikzpicture} \end{document} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.