Second Order ODE Solver using ODE23

6 views (last 30 days)
I am trying to use ode23 to solve
xy''- 1y'- 8(x^3)(y^3)=0
what I have so far is.
%%%xy''-y'-8*x^3*y^3=0
%%y''= y'/x + 8y^3x^2
% y'= x(1)
% y=x(2)
%y''= x(1)/x(1) + 8*(x(2)^3)*(x(1)^2) = 1 + 8*(x(2)^3)*(x(1)^2)
yDoublePrime = @(t,x) [x(2); 1+8*(x(1)^2)*(x(2)^3)];
tspan = [1 4];
[y,yPrime]=ode23(yDoublePrime,tspan,[0.5 -0.5])
The solution to this problem is supposed to be 0.0456, but i keep getting large vectors? It's late, I am tired, What am I missing?

Accepted Answer

Walter Roberson
Walter Roberson on 23 Oct 2017
%y''= x(1)/x(1) + 8*(x(2)^3)*(x(1)^2) = 1 + 8*(x(2)^3)*(x(1)^2)
That is incorrect. You defined y' = x(1) and y'' = x(2), but those are different x than the original x: the x(1) and x(2) are referring to the dummy parameter name to use for the function but the x is the argument to y, y(x). You could have defined y' = J(1), y'' = J(2) for the dummy arguments, and then written y''(x) = J(1)/x + 8*(J(2)^3)*(J(1)^2) on a function call with (x,J) as the arguments.
If y is a function of t (that is, if you are implying x*y(t)'' + 1 * y(t)' - 8*(x^3)*(y(t)^3), then saying that y' = x would obviously be wrong as x would become an arbitrary constant in that case, unless you want to start talking about x(t)*y(t)'' + 1 * y(t)' - 8*(x(t)^3)*(y(t)^3) ...
Anyhow, once you have that corrected, you are running a numeric simulation over x = 1 to x = 4. You cannot say that there is "a" solution: there is a result for each x along the way, and that is what you get as output, solutions at particular x. You could talk about solutions at a particular x. But remember that you are working with y' and y'' as inputs, so it is generating the integral of those for each x, so you would expect two outputs at each x, one corresponding to int(y') and the other to int(y'')
My calculations show that for y(0) = 1/2, that the system is inconsistent unless y'(0) = 0.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!