MATLAB Answers

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

조회 수: 5(최근 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일 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