2

i am stuck about drawing 6 linear functions in one graph which are

  • f_1(x)= 18x-9
  • f_2(x)= -17x+8
  • f_3(x)= -12x+6
  • f_4(x)= 4x-2
  • f_5(x)= -3x+1
  • f_6(x)= (\Pi /2)x

f_i : [0,1]-> R where i=1,2,..6 .Thanks in advance

So far I rearrange my code as

\begin{tikzpicture}%[scale=1.0]
    \begin{axis}[
width=10cm,
xlabel=$x$, ylabel=$\varphi_{i}(x)$,
ymin=-10,axis on top=true,
axis x line=middle,
axis y line=middle, 
grid=major,
legend pos=outer north east
                    ]
\addplot [blue, line width = 1, smooth, domain=0:1] {18*x-9};
\addplot [red, line width=1,smooth,domain=0:1] {-17*x +8};
\addplot [yellow, line width=1,smooth,domain=0:1] {-12*x+6};
\addplot [green, line width=1,smooth,domain=0:1] {4*x-2};
\addplot [pink, line width=1,smooth,domain=0:1] {-3*x+1};
\addplot [orange, line width=1,smooth,domain=0:1] {(3/2) *x};

\node [fill=black, circle, scale=0.3] at (axis cs: {10/21},{-3/7}) {};
\node [fill=black, circle, scale=0.3] at (axis cs: {1/2},{-1/2}) {};
\node [below left] at (axis cs: {1/2},{-1/2}) {$\frac{10}{21},\frac{-3}{7}$};
\node [below right] at (axis cs: {1/2},{-1/2}) {$(\frac{1}{2},\frac{-1}{2}$};

\legend  {$\varphi_1 (x)=18 x - 9$,
          $\varphi _2 (x)=-17x+8$,
          $\varphi_3 (x)=-12x+6$,
          $\varphi_4 (x)=4x-2$,
          $\varphi_5 (x)=-3x+1$,
          $\varphi_6 (x)=x{\displaystyle\pi/2}$
         };
    \end{axis}
\end{tikzpicture}

but i have problems in put name on intersection point. they are not look good as much as i think :)

5
  • 5
    Welcome to TeX.SE! Well, this site (mostly) not provide service "do-it-for-me". Show us, what you try so far and where you stuck in your efforts :). Then we can more easily help you. Also on the right side of your question you have listed to questions related to yours. See, if one of them is useful for you.
    – Zarko
    Mar 24 '17 at 16:38
  • i got it sorry for the language that i used :) i spend like 1.5 hours for plotting with the way i know and i am getting and getting error which is " couldn't find the pst-arrow". it was a request :3
    – Alper
    Mar 24 '17 at 16:43
  • Please show your code. I anticipate, that this error is easy to repair (but not me, I'm not pstricks man :( )
    – Zarko
    Mar 24 '17 at 16:47
  • pst-arrow was recently split from pstricks-add. You probably should update. Which distribution do you have?
    – Bernard
    Mar 24 '17 at 17:14
  • That's pgfplots code, what does pstricks or pst-arrow have to do with this? Edit: I changed the tag accordingly. Mar 24 '17 at 18:32
2

As Zarko said, TeX Stack Exchange is usually not the do-it-for-me site, but since you're new, I'll make an exception. We're going to plot with tikz and pgfplots packages (and amsmath, in case you use any exotic symbols). Here is our code.

\documentclass{article}

\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}

\usepgfplotslibrary{external}

\begin{document}

\begin{tikzpicture}
\begin{axis}[xlabel=$x$,ylabel=$y$,
xmin=-10,xmax=10,ymin=-10,ymax=10, axis lines=center, axis equal]

\addplot[domain=-10:10, color=blue,]{18*x-9};

\addplot[domain=-10:10, color=red,]{-17*x+8};

\addplot[domain=-10:10, color=yellow,]{-12*x+6};

\addplot[domain=-10:10, color=green,]{4*x-2};

\addplot[domain=-10:10, color=pink,]{-3*x+1};

\addplot[domain=-10:10, color=orange,]{pi/2*x};

\end{axis}
\end{tikzpicture}

\end{document}

And here is the result.

enter image description here

UPDATE: Sorry for not including your code in my answer, you posted it after my repsonse was already finished.

2
  • Thank you for being interested in my request, i have also get information from your code. thank you :)
    – Alper
    Mar 24 '17 at 19:06
  • No problem. I'm glad my post helped you. Have a nice day, I wish you lots of success with LaTeX.
    – God bless
    Mar 24 '17 at 19:08
1

Perhaps using a pin is a better way of highlighting those intersections. Or are you going to mark more of the intersections?

Note that I simplified the code a bit, moving domain specification and line width setting to the axis options, so that you don't to add it to all the plots.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}%[scale=1.0]
\begin{axis}[
width=10cm,
xlabel=$x$,
ylabel=$\varphi_{i}(x)$,
ymin=-10,axis on top=true,
axis x line=middle,
axis y line=middle, 
grid=major,
legend pos=outer north east,
legend style={nodes={anchor=west}}, %% added
every axis plot/.append style={ %% these will apply to all plots
  line width=1pt,
  samples=2, % don't need more for straight lines
  domain=0:1
}
]

\addplot [blue] {18*x-9};
\addplot [red] {-17*x +8};
\addplot [yellow] {-12*x+6};
\addplot [green] {4*x-2};
\addplot [pink] {-3*x+1};
\addplot [orange] {(3/2) *x};

\node [fill=black, circle, scale=0.3, pin=below:{$\bigl(\frac{10}{21},\frac{-3}{7}\bigr)$}] at (axis cs: {10/21},{-3/7}) {};
\node [fill=black, circle, scale=0.3, pin=above:{$\bigl(\frac{1}{2},\frac{-1}{2}\bigr)$}] at (axis cs: {1/2},{-1/2}) {};



\legend  {$\varphi_1 (x)=18 x - 9$,
          $\varphi _2 (x)=-17x+8$,
          $\varphi_3 (x)=-12x+6$,
          $\varphi_4 (x)=4x-2$,
          $\varphi_5 (x)=-3x+1$,
          $\varphi_6 (x)=x{\displaystyle\pi/2}$
         };
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

4
  • I write xtick={0,1} insted of arraging the points , thanks for the idea :)
    – Alper
    Mar 24 '17 at 19:05
  • @AlperErdem That also removes the grid though. Mar 24 '17 at 19:09
  • yes i aware of the consequences of that wrong move :D
    – Alper
    Mar 24 '17 at 19:14
  • @AlperErdem You could try xtick={0,1},grid=both,minor x tick num=4 if you want a grid, but no ticklabels for 0.2,0.4,0.6,0.8. Mar 24 '17 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.