Initial values for ode45 solver
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mika Maaspuro
el 21 de Mayo de 2020
Comentada: Mika Maaspuro
el 22 de Mayo de 2020
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 comentarios
Quad
el 21 de Mayo de 2020
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.
Respuesta aceptada
Bjorn Gustavsson
el 22 de Mayo de 2020
Editada: Bjorn Gustavsson
el 22 de Mayo de 2020
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
0 comentarios
Más respuestas (1)
Quad
el 22 de Mayo de 2020
Editada: Quad
el 22 de Mayo de 2020
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)
Ver también
Categorías
Más información sobre Ordinary Differential Equations 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!