Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.6K Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Help implementing DSolve on differential equations

Posted 10 years ago

hello guys, I'm pretty new to mathematica! I'm trying to plot the system of differential equations below:

system = {x' == 1-y , y' == x^2 - y^2, {x,y} , t}

can u please help me with the code? I've tried to solve it numerically with Dsolve like below:

sol = DSolve { y' =(x^2-y^2)/(1-y) , y[0] ==1 , y'[0]==2}

but my mathematica doesn't catch the first part for some reason it just keeps evaluating it to true :\ i would be grateful if u guys could help me with this :)

4 Replies

Maybe this helps:

system = {x'[t] == 1 - y[t], y'[t] == x[t]^2 - y[t]^2};
ibc = {y[0] == 1, y'[0] == 2};
sol = NDSolve[{system, ibc}, {x[t], y[t]}, {t, 0, 5}];
Plot[Evaluate[{x[t], y[t]} /. sol], {t, 0, 5},PlotLegends -> {"x[t]", "y[t]"}, PlotRange -> All]

enter image description here

POSTED BY: Mariusz Iwaniuk

Thank you so much it helped! but why does it tell me: NDSolve::icordinit: The initial values for all the dependent variables are not explicitly specified. NDSolve will attempt to find consistent initial conditions for all the variables. >>!and also is there anyway to plot some other curves with random initial value conditions?enter image description here

Because yours initial condition y'[0]=2 is very unusual(should not to be).In this case initial condition should be: {x[t0]=x0,y[t0]=y0}. Put:

ibc = {y[0] == 1, x[0] == 2};

and works fine.

You can use a ParametricNDSolve to plot some other curves.

system = {x'[t] == 1 - y[t], y'[t] == x[t]^2 - y[t]^2};
sol = ParametricNDSolve[{system, y[0] == a, x[0] == b}, {x, y}, {t, 0, 5}, {a, b}];
Plot[Evaluate[Table[x[a, b][t] /. sol, {a, 1, 5, 1}, {b, 1, 5, 1}]], {t, 0, 5}, PlotLegends -> {"x[t]"}, PlotRange -> All]

enter image description here

Plot[Evaluate[Table[y[a, b][t] /. sol, {a, 1, 5, 1}, {b, 1, 5, 1}]], {t, 0, 5}, PlotLegends -> {"y[t]"}, PlotRange -> All]

enter image description here

For more help of ParametricNDSolve

POSTED BY: Mariusz Iwaniuk

The independent variable t must be explicit: x[t], y[t], x'[t]. y'[t], and not just x,y,x',y'.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard