Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.1K Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to solve this differential equation?

Posted 10 years ago

Hi,

I'm pasting a code of a DE with scaling parameter. I'm getting error. Plz help.

Clear[x];
r=1;
eqn=x'[t]-1-r*x[t]-(x^2)[t];sol=NDSolve[{eqn,x[0]==0},x,{t,0,100}][[1]];
tTicks=Range[-24,24 30,24];
tGrid=Range[-60,24 30,6];

ParametricPlot[Evaluate[{x[t],x'[t]}/.sol],{t,0,100},Frame->True,FrameTicks->{tTicks,Automatic},FrameTicksStyle->Directive[Red,Thick],GridLines->{tGrid,Automatic},GridLinesStyle->LightGray,FrameLabel->(Style[#,14,Bold]&/@{x,Overscript[x,"."]}),AspectRatio->1]

ParametricPlot[Evaluate[{t,x[t]/.sol}],{t,0,50},Frame->True,FrameTicks->{Range[0,50,12],Automatic},FrameTicksStyle->Directive[Red,Thick],GridLines->{tGrid,Automatic},GridLinesStyle->LightGray,FrameLabel->(Style[#,14,Bold]&/@{t,x}),AspectRatio->1]

Sincerely

POSTED BY: Rahul Chakrabory
7 Replies
Posted 10 years ago
POSTED BY: Bill Simpson

Hi Bill,

The above code has helped me immensely. Thanks. But when I change the equation, like the following one it does not work.

sols=Table[x/.DSolve[{x'[t]-r*x[t]-x[t]*e^x[t]==0,x[0]==0},x,t][[1,1]],{r,1,3}] Show[Table[ParametricPlot[Evaluate[{sols[[r]][t],D[sols[[r]][t],t]}],{t,0,100}],{r,1,3}]]

regards,

POSTED BY: Rahul Chakrabory
Posted 10 years ago

I am not certain I understand what you wish to plot. Perhaps this will help

In[1]:= sols = Table[x /. DSolve[{x'[t] - 1 - r*x[t] - x[t]^2 == 0, x[0] == 0}, x, t][[1, 1]], {r, 1, 3}]

During evaluation of In[1]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. >>

During evaluation of In[1]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. >>

Out[1]= {
 Function[{t}, 1/2 (-1 + Sqrt[3] Tan[1/2 (\[Pi]/3 + Sqrt[3] t)])], 
 Function[{t}, -(t/(-1 + t))], 
 Function[{t}, -(((-3 + Sqrt[5]) (-1 + E^(Sqrt[5] t)))/(2 - 7 E^(Sqrt[5] t) + 3 Sqrt[5] E^(Sqrt[5] t)))]
}

Then perhaps you can do something like this

Table[ParametricPlot[Evaluate[{sols[[r]][t], D[sols[[r]][t], t]}], {t, 0, 100}], {r, 1, 3}]

or perhaps something like this

Show[Table[ParametricPlot[Evaluate[{sols[[r]][t], D[sols[[r]][t], t]}], {t, 0, 100}], {r, 1, 3}]]

I am uncertain whether these plots are precisely correct and you should study all these results very carefully to make certain that there are no errors.

POSTED BY: Bill Simpson

Dear Bill,

For more then one curve in a single plot , for different values of r , (r=1,2,3....) , how shall I code it?

Regards,

POSTED BY: Rahul Chakrabory
Posted 10 years ago

You might want to be cautious with your numerical solution.

Clear[x]; r = 1; eqn = x'[t] - 1 - r*x[t] - x[t]^2 == 0;
sol = x /. NDSolve[{eqn, x[0] == 0}, x, {t, 0, 100}][[1, 1]];

NDSolve::ndsz: At t == 1.2091994106422708`, step size is effectively zero; singularity or stiff system suspected. >>

And

ParametricPlot[Evaluate[{sol[t], D[sol[t], t]}], {t, 0, 100}]

enter image description here

And

Plot[sol[t], {t, 0, 100}]

enter image description here

But

Clear[x]; r = 1; eqn = x'[t] - 1 - r*x[t] - x[t]^2 == 0;
sol = x /. DSolve[{eqn, x[0] == 0}, x, t][[1, 1]];

Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. >>

And

ParametricPlot[Evaluate[{sol[t], D[sol[t], t]}], {t, 0, 100}]

enter image description here

And

Plot[sol[t], {t, 0, 100}]

enter image description here

And

In[11]:= sol

Out[11]= Function[{t}, 1/2 (-1 + Sqrt[3] Tan[1/6 (\[Pi] + 3 Sqrt[3] t)])]

Those warning messages are often there for a very good reason.

Even the warning about using Reduce is there for a good reason. Unfortunately it does not include a link to, and I have never been able to track down, a brilliantly well written paragraph in the documentation that describes exactly what that intends you to do.

POSTED BY: Bill Simpson
POSTED BY: Rahul Chakrabory
Your equation is malformed. This variation works:
eqn = x'[t] - 1 - r*x[t] - x[t]^2 == 0
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