0

I wanted to draw a parabolic graph of y=x^2 and draw the tangents and angle between tangent and graph as shown in picture using pgfplots, can any one help me out.

This type of graph

  • 6
    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Dec 23 '21 at 05:54
  • 1
    Please, consider add an example of what do you want and what problems did you come across. – scd Dec 23 '21 at 09:01
  • A parabola has infinitely many tangent lines. Are there specific points at which you wish to draw the tangents? – N. F. Taussig Dec 23 '21 at 09:12
  • In future may be helpful the answer on this question: https://tex.stackexchange.com/questions/579785/runaway-argument-in-beamer-slide (don't be confused by title, there given explanation about tangents is very educative). It is in Spanish, but it can be (by used math) easy to understand. You may also translate text to your native language. I'm confident, that aforementioned link is more helpful as one given as notice for closing of your question. – Zarko Dec 23 '21 at 16:41

3 Answers3

5

With tkz-fct / TikZ

\documentclass{standalone}
\usepackage{tkz-fct}
\begin{document}
\begin{tikzpicture}[scale=2] \tkzInit[xmax=2,ymax=4] 
\tkzGrid  \tkzAxeXY
\tkzFct[color = red,thick, domain =0:2]{x*x}
\tkzDrawTangentLine[draw, kl = 0.8, kr = 0.8](0) 
\tkzDrawTangentLine[draw, kl = 0.8,kr = 0.8 ](1) 
\end{tikzpicture}
\end{document}

enter image description here

Alain Matthes
  • 95,075
2

Have a look:

\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}

\begin{tikzpicture} \begin{axis} \addplot[color=red]{x^2}; \addplot[color=blue]{0}; \end{axis} \end{tikzpicture}

Result: enter image description here

scd
  • 774
2

Try this (wiith TikZ):

\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
    \centering
    \begin{tikzpicture}[line width=3pt,scale=1.5]
        \draw [gray!10,line width=.3pt] (-3,-1) grid (3,5);     
        \draw [->,style=thick] (-3.2,0) -- (3.3,0) node[pos=1,right] {$x$}; 
        \foreach \x in {-3,...,3} \draw[thick] (\x,-0.05) to (\x,0.05) node[black,below] at (\x,-0.05) {$\x$}; 
        \draw [->,style=thick] (0,-1.20) -- (0,5) node[pos=1,right] {$y$}; 
        \foreach \x in {-1,...,5} \draw[thick] (-0.05,\x) to (0.05,\x) node[black,left] at (-0.05,\x) {$\x$};
        \draw [cyan, domain=-2.2:2.2, samples=50] plot (\x, {\x*\x }); %parabola
        \draw [magenta, domain=0:3, samples=50] plot (\x, {2*\x- 1}); % tangent in x=1
    \end{tikzpicture}
\end{document}

enter image description here

  • Thanks for helping me out. Please can you tell me how to draw angle in between line of graph and slope as like I have updated. – Abhishek Yadav Dec 26 '21 at 09:55