ode45 solving a differential equation that has no solution for given boundary conditions
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
John D'Errico
2021-7-8
编辑:John D'Errico
2021-7-8
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!