Initial values for ode45 solver

22 ビュー (過去 30 日間)
Mika Maaspuro
Mika Maaspuro 2020 年 5 月 21 日
コメント済み: Mika Maaspuro 2020 年 5 月 22 日
I'm trying to solve second degree ordinary differential equations numerically.
I tried ode45 solver. It requires the span tspan[y0,yn] and the inital values y0 = [f(y=0),f'(y=0].
In my problem I don't know f'(y=0), but I could give f''(y=yn). Is there any way to do this?
I have tried also the symbolic math solver. There is a way to do this. However, some of
my equations cannot be solved using the symbolic math solver.
  2 件のコメント
Quad
Quad 2020 年 5 月 21 日
What symbolic math solver? Have you tried dsolve?
Do you have f"(0)? If you do, then you should be able to calculate f'(0). Out of f(y), f'(y), and f''(y) for y=0 or y=yn you must know at least two in order to solve numerically using an ODE solver. If you know the conditions at the end you can solve backwards, if you know the conditions at the beginning you can solve forwards. If you have the final conditions and want to integrate backwards, look here
You can also consider trying to setup the problem as a boundary problem and use a function such as bvp4c (or bvp5c) depending on what all information you have.
The matlab ODE solvers are doing numerical integration and cannot do so without the initial conditions. If it could accept symbolic variables as the initial conditions then the result would be every itteration in terms of the initial condition, which wouldn't do much good to have. A differential equation without an analytical solution must be solved as an initial value problem or boundary problem (assuming a solution exists). Without knowing where a system begins/the constraints it is imposible to numerically say how it will evolve.
Mika Maaspuro
Mika Maaspuro 2020 年 5 月 22 日
Thank you for the answer.
I checked the link to bpv4c. There was instructions to reverse the tspan. In that case I would need initial conditions for the end point (both the value and the first derivate). In my case I know only f(0) and df(yn)/dy. So the tspan reverse does not solve this problem. With bpv4c there is a way to enter boundary conditions f(0), f(yn), but not derivatives(?), but again I miss the f(yn). In integration of the equation I will get integration constants and I think these two known boundary values might not be enough for solving the integration constants.
My equations are like: d2f/dy -(1/(1-y)) df/dy - 2*(5/(201*1e-3)) * f = 0
this one I solved with the symbolic solver and by that way I get df(0)/dy. Using this value with the numerical solver I got the same result. However, some of my equations will not be solved using the symbolic solver and I need to use the numeric solvers.
How I could manage solve the equations while only f(0) and df(yn)/dy are known and f(yn) and df(0)/dy are unknown? If you think integration is the way to proceed, which Matlab function you propose to use?

サインインしてコメントする。

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 5 月 22 日
編集済み: Bjorn Gustavsson 2020 年 5 月 22 日
If bvp4/5c doesn't handle this type of problems then this sounds like a setup for using the shooting method. Simply build a function that integrates your ODE from t0 to tn with one input parameter (f'(y=0)), that returns f'(y=yn). Now you have a function that you can use for minimization:
dfdy0best = fminsearch(@(dfdy0) (dfdyn - odeintegrationings(dfdy0,f0,t_span))^2,1)
where odeintegrationings look something lilke this:
function dfdyn = odeintegrationings(dfdy0,f0,y_span)
f0dfdy0 = [f0;dfdy0];
[~,fdf] = ode45(@(t,y) your_ode(t,y),t_span,f0dfdy0);
dfdyn = fdf(end,2);
end
However, that differential equation surely has some known analytical solution that you should be able to find...
HTH

その他の回答 (1 件)

Quad
Quad 2020 年 5 月 22 日
編集済み: Quad 2020 年 5 月 22 日
Well, I may not be understanding what the problem is, but bvp4c does indeed allow you do use a derivative as a boundary condition. Here is a simple example using ode45 (with proper initial conditions) and bvp4c (with f(yn=0) and f '(yn):
odeFun = @(t,x) [ x(2);
-2*x(1)-x(2)];
x0 = [5,1];
span = [0,10];
[t,state]=ode45(fun,span,x0);
% Grab last f' value to use in bvp4c
df_end = state(end,2);
f0 = x0(1);
% Make boundary conditions function
bc = @(ya,yb) [ya(1)-f0;
yb(2)-df_end];
% Solve
solinit = bvpinit(t,[0,1]);
sol = bvp4c(odeFun,bc,solinit);
y = deval(sol,t);
figure;
plot(t,state(:,1)); hold on;
plot(t,y(1,:),'--');
legend('ode45','bvp4c');
Note that the state vector is . So to specify a f' as a the second boundary condition you need to specify yb(2) because f' is the second value in the state vector. ya(1) specifies the left condition as f(y=0), and yb(2) specifies the right boundary as f '(yn)
  1 件のコメント
Mika Maaspuro
Mika Maaspuro 2020 年 5 月 22 日
Thank's, this solves my problem.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by