Hi all, I am trying to solve a fourth order differential equation using bvp4c.Below is my code.Can anyone help me to find the mistake in my code for which matlab is showing the following error?Thanks you
1 view (last 30 days)
Show older comments
function sol = Fig1
solinit=bvpinit(linspace(0,30,50),@guess);
sol=bvp4c(@cantileverode,@cantileverbc,solinit);
xint=linspace(0,30,50);
Sxint=deval(sol,xint);
axis('auto')
function dy=cantileverode(x,y,l,F)
l=17.6e-3;
F=0.026;
dy=zeros(4,1);
dy(1)=y(2);
dy(2)=y(3);
dy(3)=y(4);
dy(4)=(1/l^2)*(y(3)+F*cos(y(1)));
function res=cantileverbc(ya,yb,l,F)
res=[ya(1)
ya(2)
yb(3)
yb(4)];
function v =guess(x)
v=[(30-x)^4*x^2*exp(x);-4*(30-x)^3*x^2*exp(x)+(30-x)^4*(x^2*exp(x)+2*x*exp(x))];
and the errors are as follows;
Attempted to access y(3); index out of bounds because numel(y)=2.
Error in Fig1>cantileverode (line 10) dy(2)=y(3);
Error in bvparguments (line 105) testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 129) [n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] = ...
Error in Fig1 (line 3) sol=bvp4c(@cantileverode,@cantileverbc,solinit);
0 Comments
Accepted Answer
Torsten
on 2 Nov 2015
You will have to supply guesses for y, y', y'' and y'''.
Your guess function only contains two components.
Best wishes
Torsten.
5 Comments
More Answers (1)
Torsten
on 2 Nov 2015
function main
l=17.6e-3;
F=0.026;
solinit=bvpinit(linspace(0,30,50),@guess);
sol=bvp4c(@(x,y)cantileverode(x,y,l,F),@(ya,yb)cantileverbc(ya,yb,l,F),solinit);
xint=linspace(0,30,50);
Sxint=deval(sol,xint);
axis('auto')
function dy=cantileverode(x,y,l,F)
dy=[y(2)
y(3)
y(4)
(1/l^2)*(y(3)+F*cos(y(1)))];
function res=cantileverbc(ya,yb,l,F)
res=[ya(1)
ya(2)
yb(3)
yb(4)];
function v =guess(x)
v=[(30-x)^4*x^2*exp(x)
-4*(30-x)^3*x^2*exp(x)+(30-x)^4*(x^2*exp(x)+2*x*exp(x))
Insert v''
Insert v'''];
I'm too lazy to calculate v'' and v'''.
You will have to insert them in the last two lines of the code.
Best wishes
Torsten.
11 Comments
Torsten
on 3 Nov 2015
Usually it means that the boundary conditions are insufficient to fix a unique solution.
Best wishes
Torsten.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!