0

Can anybody help me to draw these figures in Latex? Sorry I'm new in Latex, so I really don't know how to do it. And is it possible to do it, where you can actually see the slope field (I know you really can't in the picture)? And how would I do, if I only wan't the x-axis and y-axis to be shown, and not the whole rectangle, as they have done in the picture? Hope somebody can help a new person in Latex! slope field

2
  • 1
    Welcome! This has been achieved in this answer. – user194703 Mar 16 '20 at 16:55
  • I see. Thanks. But what if I also want the explaining text in the slope field. Like y(0)=-3 etc, with a line to the particular solution that satisfy that condition? And the dot? Is that possible? – Jasmin Hansen Mar 16 '20 at 17:04
1

This is not an attempt to solve a second order differential equation with LaTeX (even though it can be done). It is much easier to solve the differential equation analytically and to plot the solutions.

\documentclass[fleqn]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
The equation
\[ y''+3y'+2y=0 \]
has the solution
\[y(x)=a\,\mathrm{e}^{-x}+b\,\mathrm{e}^{-2x}\;,\]
where $a$ and $b$ are fixed by the boundary conditions. Demanding that
\[
 y(0)=u\quad\text{and}\quad y'(0)=v
\]
the solution becomes (cf.\ Figure~\ref{fig:sols})
\[
 y(x)=(2\,u+v)\,\exp(-x)+(-u-v)\,\exp(-2*x)\;.
\]


\begin{figure}[h]
\centering
\begin{tikzpicture}[declare function={%
    ysol(\x,\u,\v)=(2*\u+\v)*exp(-\x)+(-\u-\v)*exp(-2*\x);}]
 \begin{axis}[ymin=-3,ymax=3,domain=-1:5,width=0.45\textwidth,
    title={$y(0)=1$ and $y'(0)$ varies.}]
  \pgfplotsinvokeforeach{-6,-4,-2,0,2,4,6}
  {\addplot[color=blue,no marks,smooth] {ysol(x,1,#1)};}
 \end{axis}
 \begin{axis}[ymin=-5,ymax=5,domain=-2:4,width=0.45\textwidth,xshift=.5\textwidth,
    title={$y'(0)=1$ and $y(0)$ varies.}]
  \pgfplotsinvokeforeach{-3,-2,-1,0,1,2,3}
  {\addplot[color=blue,no marks,smooth] {ysol(x,#1,1)};}
 \end{axis}
\end{tikzpicture}
\caption{Solutions of $y''+3y'+2y=0$.}
\label{fig:sols}
\end{figure}
\end{document}

enter image description here

0

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.