How to solve differential equation

Hi ,
Can someone check my codes written below and find out the error in it?
1.dx/dt +x^2=0 , x(0)=x0 --> The solution should be x(t)=x0*exp((-x^2 )*t)
syms x(t) a x0
Dx=diff(x)
dsolve(Dx==-x.^2,x(0)==x0)
I'm getting
ans =1/(t + 1/x0) which I know, is wrong.
2.d2y/dt2+ w^2y=0 y(0)=y0 , dy/dt(0)=v0
My code:
syms y(t) w y0 v0
Dy=diff(y)
D2y=diff(y,2)
dsolve(D2y==-w^y, y(0)==y0,Dy(0)==v0)
Regards
Swati

4 Comments

The solution for the first one given by matlab is correct.
If you examine the equation that you suppose to be correct you will see that it has x(t) on both sides of the solution, which would not be the case for a correct solution. A correct solution has to be determined only by x0 and t.
@Walter Roberson
Since I've considered x0 and t as symbolic variables, I was execting to get the final soltion as x(t)=x0*exp((-x^2 )*t , the solution 1/(t + 1/x0) [ given by MATLAB] is nowhere close to the final solution because of the absence of exponenetial term in it.
If hypothetically there were an exponential term in the solution then it would have to be exponential in t and not x.
Have you taken your proposed exponential solution and substituted it into the differential equation to verify that it works? I believe that you will find that it does not work.
That nonlinear differential equation can be solved with separation of variables.
You get:
That one you integrate from t0 to t giving you the solution matlab gave you. For a general solution of ODEs of this kind have a look at: Ricatti equation.

Sign in to comment.

Answers (0)

Categories

Asked:

on 29 Jan 2020

Commented:

on 29 Jan 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!