ode45 solving a differential equation that has no solution for given boundary conditions
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ankit Singh
el 8 de Jul. de 2021
Comentada: Ankit Singh
el 9 de Jul. de 2021
Hi ,
I used the ode45 to solve a second order differential equation by manipulating it with symbolic toolbox first. The ode45 solves the system of first order differential equatio obtained from the toolbox instead of giving an error.
Does the ode45 return an error if the boundary value problem has no solution?
Here is what i did..
syms x(t)
eqn = diff(x,2) + x == 0
[V] = odeToVectorField(eqn)
M = matlabFunction(V,'vars',{'t','Y'})
sol = ode45(M ,[0 pi],[1 1])
there s no solution for f(0) = 1 and f(pi) = 1 ..but the solver still solves but solves incorrectly ..of course
0 comentarios
Respuesta aceptada
John D'Errico
el 8 de Jul. de 2021
Editada: John D'Errico
el 8 de Jul. de 2021
So, you formulated a 2nd degree ODE. Converted it as:
syms x(t)
eqn = diff(x,2) + x == 0
[V] = odeToVectorField(eqn)
M = matlabFunction(V,'vars',{'t','Y'})
Then you created TWO initial conditions. You did not formulate a boundary value problem, which ODE45 is NOT designed to handle. It handles INITAL value problems.
sol = ode45(M ,[0 pi],[1 1])
That second argument is the span in t to solve over. It does NOT tell ODE45 to solve the problem you thought you were solving. READ THE HELP!
So the solution it returns looks like this:
plot(sol.x,sol.y(1,:))
Did you think that call told ODE45 to solve a problem with x(0) = 1, and x(pi) == 1? WRONG. As you should see, x'(0) looks to be 1.
That call told ODE45 to solve the problem where x(0) == 1, AND x'(0) == 1. Does that have a solution? Of course it does!
dx = diff(x,t,1);
xsol = dsolve(eqn,x(0) == 1,dx(0)==1)
fplot(xsol,[0,pi])
It should be no surprise the two look alike.
Again, ODE45 is NOT a boundary value solver.
Now, what happens if you decide to solve the problem you wanted to solve? First in symbolic form:
xsolb = dsolve(eqn,x(0) ==1, x(pi) == 1)
So dsolve could not find a solution. (Hey, you got that correct.) Now it would seem more appropriate to use a solver like bvp4c.
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!