Effacer les filtres
Effacer les filtres

MATLAB solving BVP using bvp4c

8 vues (au cours des 30 derniers jours)
Taylor Nichols
Taylor Nichols le 4 Oct 2018
Commenté : Torsten le 5 Oct 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.
  1 commentaire
Torsten
Torsten le 5 Oct 2018
What is h' ?

Connectez-vous pour commenter.

Réponse acceptée

Torsten
Torsten le 5 Oct 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 commentaires
Taylor Nichols
Taylor Nichols le 5 Oct 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 le 5 Oct 2018
https://en.wikipedia.org/wiki/Ordinary_differential_equation
Section "Reduction of order"

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by