0

I asked a question some time ago about a trajectory graph of a vector field in Mathematica, my question is: Is it possible to generate this graph directly in LaTeX?

I am using this parametric solution provided by Wolfram,

``

I will put the initial data (3,pi/2) doing the calculations I got that c_1=-1/64 and c_2=0.90778 now I tried to graph this parametric solution but no i get nothing.

Input

\documentclass{standalone}  
\usepackage{tkz-fct}

\begin{document}

\begin{tikzpicture}[scale=1] \tkzInit[xmin=-3,xmax=3,xstep=1,ymin=-3,ymax=3,ystep=1] \tkzAxeX[step=1] \tkzAxeY[step=1] \tkzFctPar[samples=400,domain=0:2000]{(1/2)(2+sqrt(4+(2(-2t+sqrt(t+0.015625)+2))/(t+0.015625)))cos(0.9078+(2/3)cos((3(t+0.015625)^(1/4))/sqrt(2)))}{(1/2)(2+sqrt(4+(2(-2t+sqrt(t+0.015625)+2))/(t+0.015625)))sin(0.9078+(2/3)cos((3(t+0.015625)^(1/4))/sqrt(2)))} \end{tikzpicture}

\end{document}

With this initial point, I was looking for the blue trajectory to come out.

enter image description here

Zaragosa
  • 599
  • 4
    Yes it is possible. You need to show compilable code of what your have tried and you need to explain what is causing you problems. You could start by googling "How to plot parametric function in LaTeX" – hpekristiansen Jan 28 '23 at 01:37
  • @hpekristiansen You mean this? DSolve[{r'[t] == -(r[t] - 1)^5, [Theta]'[t] == Piecewise[{{0, r[t] == 1}, {-(r[t] - 1)^3 Sin[3/(2 (r[t] - 1))], r[t] != 1}}]}, {r, [Theta]}, t] // Simplify – Zaragosa Jan 28 '23 at 02:16
  • 5
    No. I mean you need to try to do it. This site is not for do it for me type of questions. Edit your question to contain compilable LaTeX code. – hpekristiansen Jan 28 '23 at 02:23
  • Depends on your definition of possible. If you generate a list of coordinates in Mathematica then copy paste it into your LaTeX source, then yes it's obviously possible. (← this is the practical option, most other options are quite difficult to implement.) – user202729 Jan 28 '23 at 04:13
  • Actually, looking at the linked answer there's a parametric solution, so just throw it into pgfplots. As long as it has enough precision and is fast enough... (can use Lua backend) – user202729 Jan 28 '23 at 04:16
  • Does it require solving an ODE? You could use a previous question of yours as a starting point. – AlexG Jan 28 '23 at 12:27
  • @hpekristiansen The code that I put above is one of my failed attempts, although there is no error anywhere, I do not understand why it does not graph anything. I will continue trying now not with the parametric solution but now with the ODE directly, whatever I add to the code obtained. – Zaragosa Jan 28 '23 at 13:36
  • @AlexG Yes, it was my first option but in said ODE it is in Cartesian coordinates but here I have it in polar coordinates, and the solution will come out in polar coordinates so I don't know what to put in \listplotThreeD[...]{XYZa} – Zaragosa Jan 28 '23 at 13:43

1 Answers1

2

Math solution taken from https://mathematica.stackexchange.com/a/271381 and with random chosen constants.

\documentclass[tikz, border=1cm]{standalone}  
\usepackage{pgfplots}  
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[
declare function={
r=1+(\rz-1)/(1+4*(-1+\rz)^4*t)^(1/4);
theta=1/3*(3*\thetaz-2*cos(3/(2*(-1+\rz))))+2/3*cos((3*(1+4*(-1+\rz)^4*t)^(1/4))/(2*(-1+\rz)));
},
]
\begin{axis}[
xmin=-2, xmax=1.5,
ymin=-1, ymax=3,
trig format plots=rad,
axis equal,
enlargelimits={abs=0.1},
minor tick num=4,
]
\pgfmathsetmacro{\rz}{1.8}
\pgfmathsetmacro{\thetaz}{1}
\addplot[blue, thick, domain=0:2000, samples=500, variable=t, smooth] ({r*cos(theta)},{r*sin(theta)});
\pgfmathsetmacro{\rz}{0.5}
\pgfmathsetmacro{\thetaz}{5}
\addplot[brown, thick, domain=0:2000, samples=500, variable=t, smooth] ({r*cos(theta)},{r*sin(theta)});
\pgfmathsetmacro{\rz}{2}
\pgfmathsetmacro{\thetaz}{3}
\addplot[green!50!black, thick, domain=0:2000, samples=500, variable=t, smooth] ({r*cos(theta)},{r*sin(theta)});
\draw[red, thick] (0,0) circle[radius=1];
\end{axis}
\end{tikzpicture}
\end{document} 

Graph with three colored zigzags and a red circle

  • Wow excellent answer, I still have a lot to learn. A query is it possible to add dates in the trajectories? I made this: \addplot[blue, thick, domain=0:4500, samples=1000, variable=t, smooth, -stealth] but I only get one arrow obviously, I'm thinking about how to put 3 or 4 arrows inside the trajectories if you have any advice I would really appreciate it. – Zaragosa Jan 29 '23 at 00:53
  • You could use decorations.markings - there are many post about using it see e.g. the arr style defined here: https://tex.stackexchange.com/a/670856/8650 – hpekristiansen Jan 29 '23 at 01:17
  • Thank you for that – Zaragosa Jan 29 '23 at 01:21