I wanted to draw following graphs of two general functions of Geometric interpretation of the Euler method. Thanks in advance enter image description here

  • 3
    Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document.
    – magula
    Commented Oct 3, 2017 at 12:04
  • 3
    The question is not clear what aspect of plotting these graphs the OP needs help with. They both are reasonably complicated and a lot of work to build as a whole in one answer.
    – lblb
    Commented Oct 3, 2017 at 14:08
  • Two general functions? Do you mean f(x) and the tangent line?. ... Do you want this graph for any function f, with defined x-step h?
    – Bobyandbob
    Commented Oct 4, 2017 at 6:43
  • @Bobyandbob Yes, exactly
    – Janeth_A
    Commented Oct 4, 2017 at 14:18

2 Answers 2


Using the tzplot package:

enter image description here



% \tzhelplines(9,7)
% intersections
% projections on x-axis
\tzprojsx[thick](C){$t_i$}(A){$t_{i+1}$}; % version 2
% horizontal dashed lines
% labels
\tzline+[->](3,3.5){Tangent line}[at start,a](2.5,-1)
       (C|-{0,-1.5ex}){$h$}[inner sep=2pt,centered,fill=white]


A try with the function f(x)=scale*x^2. If i have time i will clearify my comments.

My approach contains 5 parameters:

  • x-value of t_i: \pgfmathsetmacro\TI{1.5}
  • x-value of t_{i+1}: \pgfmathsetmacro\TIplusone{3.5}
  • scale of the function: \pgfmathsetmacro\scale{0.2} <=> (f(x)=scale*x^2)
  • slope/gradient m of the function: \pgfmathsetmacro\m{\scale*2*\TI}
  • intercept b of the function: \pgfmathsetmacro\b{\scale*\TI*\TI-\m*\TI}

Math (Background)

Given function:


Finding the tangent line from f(x) in Point P(t_i,u_i):

1.) Compute slope

m = f'(t_i) = 0.3*2*t_i
m = f'(1.5) = 0.3*2*1.5

2.) insert P in line function

u_i = m * t_i+ b => b= ...

3. tangent line:

y = m*x+b


enter image description here





\pgfmathsetmacro\m{\scale*2*\TI} % slope/gradient, f = \scale*\x*\x -> f'= \scale*2*x_0
\pgfmathsetmacro\b{\scale*\TI*\TI-\m*\TI} %intercept


%custom dash pattern from https://tex.stackexchange.com/a/101263/124842
    dot diameter/.store in=\dot@diameter,
    dot diameter=1.5pt,
    dot spacing/.store in=\dot@spacing,
    dot spacing=5pt,
        line width=\dot@diameter,
        line cap=round,
        dash pattern=on 0pt off \dot@spacing

% axis
\draw[->] (\domainStart-0.2,0) -- (\domainEnd+0.2,0) node[right] {$x$};
\draw[->] (\domainStart,-0.2) -- (\domainStart,\domainEnd) node[right] {$x$};

% functions
\draw[color=blue] plot (\x,\scale*\x*\x) node[right] {$f(x) =\scale*x^2$};
\draw[color=black] plot (\x,\m*\x+\b);% node[right] {$f'(x) =0.1*2*x$};
% dots
\draw[dots] (\TI,0) -- (\TI,\m*\TI+\b) node[below,pos=0] (A) {$t_i$};
\fill (\TI,\m*\TI+\b)  circle[radius=2pt];
\fill (\TIplusone,\m*\TIplusone+\b)  circle[radius=2pt];
\draw[dots] (\TIplusone,0) -- (\TIplusone,\scale*\TIplusone*\TIplusone) node[below,pos=0] (B) {$t_{i+1}$};
\fill (\TIplusone,\scale*\TIplusone*\TIplusone)  circle[radius=2pt];

% error
\draw[black,<->] (\domainEnd+0.2,\m*\TIplusone+\b)  -- (\domainEnd+0.2,\scale*\TIplusone*\TIplusone) node[right,pos=0.5] {error};

% h
\draw[black,<->] (A)  -- (B) node[pos=0.5,fill=white,inner sep=0.5pt] {h};

%  y-ticks
\draw[dashed] (\domainStart,\m*\TI+\b+0.2) -- (\domainEnd,\m*\TI+\b+0.2) node[left,pos=0] {$u_{i}$};
\draw[dashed] (\domainStart,\m*\TIplusone+\b+0.2) -- (\domainEnd,\m*\TIplusone+\b+0.2) node[left,pos=0] {$u_{i+1}$};
\draw[dashed] (\domainStart,\scale*\TIplusone*\TIplusone+0.2) -- (\domainEnd,\scale*\TIplusone*\TIplusone+0.2) node[left,pos=0] {$y(t_{i+1})$} ;
  • I appreciate your help!
    – Janeth_A
    Commented Oct 5, 2017 at 4:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .