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 Oct 3 '17 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 Oct 3 '17 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 Oct 4 '17 at 6:43
  • @Bobyandbob Yes, exactly – Janeth_A Oct 4 '17 at 14:18

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})$} ;
| improve this answer | |
  • I appreciate your help! – Janeth_A Oct 5 '17 at 4:15

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.