amcavoy
- 663
- 0
I know how to solve them in Mathematica, but is there a way I can plot slope fields / integral curves?
The discussion revolves around plotting slope fields and integral curves for differential equations using Mathematica. Participants share methods and code snippets for achieving these visualizations, exploring both standard packages and custom functions.
Graphics`PlotField` and provides a code snippet for defining functions with DSolve or NDSolve.Participants generally agree on the methods to plot slope fields and integral curves, but there are unresolved issues regarding the functionality of the simplified code version. Some participants successfully implement the longer method while others struggle with the cut-down version.
Limitations include potential typos in code snippets and the need for proper execution of package loading commands. The discussion does not resolve the effectiveness of the simplified approach.
yes there isapmcavoy said:I know how to solve them in Mathematica, but is there a way I can plot slope fields / integral curves?
<<Graphics`PlotField`
<<Graphics`Arrow`
sol1=NDSolve[{y'[x]==y[x]-x,y[0]==0.5},y,{x,0,3}];
fsol[x_]:=Evaluate[y[x]/.Flatten[sol1]];
xpt=2.6
xed=2.7
ypt=fsol[2.6]
yed=fsol[2.7]
a1=Graphics[Arrow[{xpt,ypt},{xed,yed}]];
pv=PlotVectorField[{1,y-x},{x,-3,3},{y,-3,3},PlotRange->{{-4,4},{-4,4}},
PlotPoints->25,Axes->True]
pt1=Plot[fsol[x],{x,0,2.7},PlotStyle->{{Thickness[0.01]}}]
Show[{pv,pt1,a1}]
apmcavoy said:I'm not on my home computer now, but I will post it tomorrow most likely. I would have thought Wolfram would have a quicker way to do this, but I guess this is it. Thanks a lot saltydog for the information! I will try that out as soon as possible.
<<Graphics`PlotField`
sol1=NDSolve[{y'[x]==y[x]-x,y[0]==0.5},y,{x,0,3}];
pt1=Plot[Evaluate[y[x]/.sol1]
pv=PlotVectorField[{1,y-x},{x,-3,3},{y,-3,3}]
Show[{pt1,pv}]
apmcavoy said:The longer way worked great. However, I couldn't get the cut-down version to work properly. Any ideas why? Thanks saltydog.
<<Graphics`PlotField`
sol1=NDSolve[{y'[x]==y[x]-x,y[0]==0.5},y,{x,0,3}];
pt1=Plot[Evaluate[y[x]/.sol1,{x,0,3}]
pv=PlotVectorField[{1,y-x},{x,-3,3},{y,-3,3}]
Show[{pt1,pv}]