- #1

- 665

- 0

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Mathematica
- Thread starter amcavoy
- Start date

- #1

- 665

- 0

- #2

lurflurf

Homework Helper

- 2,440

- 138

yes there isapmcavoy said:

- #3

- 665

- 0

Well, how would I do it?

- #4

lurflurf

Homework Helper

- 2,440

- 138

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

- #5

saltydog

Science Advisor

Homework Helper

- 1,590

- 3

Hey Apmcavoy, can you follow this (note the double equal signs):

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.

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.

Last edited:

- #6

- 665

- 0

- #7

saltydog

Science Advisor

Homework Helper

- 1,590

- 3

apmcavoy said:

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}]
```

- #8

- 665

- 0

- #9

saltydog

Science Advisor

Homework Helper

- 1,590

- 3

apmcavoy said:

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}]
```

Share:

- Replies
- 5

- Views
- 2K

- Last Post

- Replies
- 5

- Views
- 11K