ode45 solving a differential equation that has no solution for given boundary conditions

3 ビュー (過去 30 日間)
Ankit Singh
Ankit Singh 2021 年 7 月 8 日
コメント済み: Ankit Singh 2021 年 7 月 9 日
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


John D'Errico
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
eqn(t) = 
[V] = odeToVectorField(eqn)
V = 
M = matlabFunction(V,'vars',{'t','Y'})
M = function_handle with value:
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])
sol = struct with fields:
solver: 'ode45' extdata: [1×1 struct] x: [0 0.2010 0.5151 0.8293 1.1434 1.4576 1.7717 2.0859 2.4001 2.7142 3.0284 3.1416] y: [2×12 double] stats: [1×1 struct] idata: [1×1 struct]
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:
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)
xsol = 
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)
Warning: Unable to find symbolic solution.
xsolb = [ empty sym ]
So dsolve could not find a solution. (Hey, you got that correct.) Now it would seem more appropriate to use a solver like bvp4c.
  1 件のコメント
Ankit Singh
Ankit Singh 2021 年 7 月 9 日
ahh..my bad. should have carefully read the ode45 help. thank for the nice explanation.


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by