MATLAB solving BVP using bvp4c

8 次查看(过去 30 天)
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.

采纳的回答

Torsten
Torsten 2018-10-5
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 个评论
Taylor Nichols
Taylor Nichols 2018-10-5
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 2018-10-5
https://en.wikipedia.org/wiki/Ordinary_differential_equation
Section "Reduction of order"

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Boundary Value Problems 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by