Borrar filtros
Borrar filtros

MATLAB solving BVP using bvp4c

8 visualizaciones (últimos 30 días)
Taylor Nichols
Taylor Nichols el 4 de Oct. de 2018
Comentada: Torsten el 5 de Oct. de 2018
I am trying to solve a BVP in matlab using the bvp4c function. The following equation is a 3rd order linear homogeneous ODE with constant coefficients. I have solved second order linear and non-linear but I can't seem to figure out how to do a third order. I cannot find and documentation on how to make this adjustment.
The equation: y''' = a*h'
with boundary conditions y(0) = 0.3; y(15) = 0.7; y'(0) = 0;
The main code I have tried is below:
init = bvpinit(linspace(1,15,10),[0,0]);
sol = bvp4c(@rhs_bvp, @bc_bvp, init);
x = linspace(1,15,100);
BS = deval(sol, x);
plot(x,BS(1,:));
using the bc_bvp funtion below:
function [ bc ] = bc_bvp( yl, yr )
hi = 0.3;
ho = 0.7;
bc = [yl(1) - hi;
yl(2);
yr(1) - ho];
end
and the rhs_bvp function below:
function [ rhs ] = rhs_bvp( x, y )
a = 26;
rhs = [y(3); a*y(2)];
end
and I get this error:
Index exceeds matrix dimensions.
Error in rhs_bvp (line 8)
rhs = [y(3); a*y(2)];
Error in bvparguments (line 105)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 130)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Any help would be greatly appreciated.

Respuesta aceptada

Torsten
Torsten el 5 de Oct. de 2018
If h' = y', try
function main
init = bvpinit(linspace(1,15,10),[0,0,0]);
sol = bvp4c(@rhs_bvp, @bc_bvp, init);
x = linspace(1,15,100);
BS = deval(sol, x);
plot(x,BS(1,:));
end
function [ rhs ] = rhs_bvp( x, y )
a = 26;
rhs = [y(2); y(3); a*y(2)];
end
function [ bc ] = bc_bvp( yl, yr )
hi = 0.3;
ho = 0.7;
bc = [yl(1) - hi;
yl(2);
yr(1) - ho];
end
Best wishes
Torsten.
  2 comentarios
Taylor Nichols
Taylor Nichols el 5 de Oct. de 2018
Thanks for the help Torsten! I guess including a picture of how I broke down the function would've helped. So if we have a 3rd order function we need to have 3 initial guesses? I'm also confused on why we set up the rhs variable that way too. I have only seen examples on 2nd order. And no detailed documentation on using this method exist. If you have anymore quick pointers it would be greatly appreciated!
Torsten
Torsten el 5 de Oct. de 2018
https://en.wikipedia.org/wiki/Ordinary_differential_equation
Section "Reduction of order"

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by