ode does not appear to give correct answer

5 visualizzazioni (ultimi 30 giorni)
Can anybody help with this very simple ode problem?
Here is the differential equation that I am trying to solve with MATLAB: dy/dx = (4*x^2)/y .
The answer should be: y = ±√((8x^3)/3+2c)
But the answer that MATLAB gives me is: (2^(1/2)*3^(1/2)*(4*x^3 + C1)^(1/2))/3
-(2^(1/2)*3^(1/2)*(4*x^3 + C1)^(1/2))/3 . In simpler terms, it gives me y = ±√((8x^3)+2c)/3. It differs from what I get 'on paper' because the 2c is also divided by 3 and I don't believe that it should be.
What am I doing wrong? Here is my code:
ode = diff(y,x) == (4*x^2)/y
ysol(x) = dsolve(ode)

Risposta accettata

John D'Errico
John D'Errico il 30 Nov 2021
Modificato: John D'Errico il 30 Nov 2021
I think you misunderstand what is happening.
You get a constant in there, in the form of 2*c. But is c an unknown constant? Would it have mattered if the solution merely had c in there? My point is an extra scalar value multiplied by the constant is irrelevant. If you have 2*c/3, is c still an unknown constant? YES!
So are you doing something "wrong" Well, yes, and no. The error you have is in your expectation and understanding of what does it mean to have an unknown constant. Both solutions are equally valid. They just end up with subtly different variations on a completely unknown constant. And all of this is effectively caused because you have provided no initial condition for the ODE.
syms y(x)
ODE = diff(y) == 4*x^2/y;
If I now try to solve that ODE without an initial condition, I will get an unknown constant. It arises because there is no initial condition, that allows dsolve to eliminate the unknown constant.
dsolve(ODE)
ans = 
So there we see two solutions, both of which have an unknown constant. The two solutions arise because there is a square root. I can resolve the constant by including an initial condition of course.
dsolve(ODE, y(0) == 1)
ans = 
Now there are no arbitrary factors of 2 or 3, because the constant is now KNOWN, and even better, one of the solutions has disappeared.
That factor of 2 or 3 on an unknown constant is just a mirage.
  1 Commento
Aisling Lynch
Aisling Lynch il 30 Nov 2021
Thanks John. I understand. I just expected MATLAB to give me the same answer that I got 'on paper'! What you have said makes perfect sense.
Thanks for your help.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by