Differential Equations in Mathematica

Click For Summary

Discussion Overview

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.

Discussion Character

  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • Some participants inquire about methods to plot slope fields and integral curves in Mathematica.
  • One participant suggests using the standard package Graphics`PlotField` and provides a code snippet for defining functions with DSolve or NDSolve.
  • Another participant shares a more streamlined version of the code but notes that it requires proper execution of the package loading line in a separate cell.
  • Several participants express gratitude for the shared information and indicate plans to try the suggested methods.
  • One participant encounters issues with the simplified code and seeks clarification on potential errors, later admitting to typos in their initial attempt.

Areas of Agreement / Disagreement

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.

Contextual Notes

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.

amcavoy
Messages
663
Reaction score
0
I know how to solve them in Mathematica, but is there a way I can plot slope fields / integral curves?
 
Physics news on Phys.org
apmcavoy said:
I know how to solve them in Mathematica, but is there a way I can plot slope fields / integral curves?
yes there is
 
Well, how would I do it?
 
There is a standard package
Graphics`PlotField`
that may be helpfull
all you need for particular curves is to define a function using DSolve or NDSolve
f[x_,x0_,y0_]:=NDSolve[{y'[x]+y[x]==0,y[x0]==y0},y[x],{x,y0,10}][1,1,2]
for the slope field use the DE to get the slope
 
Hey Apmcavoy, can you follow this (note the double equal signs):

Code:
<<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}]

A plot of the results is attached. If so, can you post the same for your differential equation?

Edit: Alright, you don't need some of that stuf: arrow tip at the end of the curve, the axes->True, thickness, plotstyle, plotpoints. Just take them out to cut it down.
 

Attachments

  • slope field.JPG
    slope field.JPG
    26.3 KB · Views: 615
Last edited:
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.
 
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.

Quicker? How about this stripped-down version:

Code:
<<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}]
 
The longer way worked great. However, I couldn't get the cut-down version to work properly. Any ideas why? Thanks saltydog.
 
apmcavoy said:
The longer way worked great. However, I couldn't get the cut-down version to work properly. Any ideas why? Thanks saltydog.

Alright I'm sorry. That's what I get for posting it without trying it first. Some typos: (no x range in Plot). Also the <<Graphics line should be in it's own cell as it needs to be executed only once to load the package (PlotField is a library of functions).

Code:
<<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}]
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K