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
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);
Accepted Answer
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
Richardson Joseph
on 2 Nov 2015
Torsten
on 2 Nov 2015
Does the solution look reasonable despite the warning?
If yes: Try to increase NMax in the option settings for bvp4c:
options = bvpset('NMax',10000);
sol=bvp4c(@(x,y)cantileverode(x,y,l,F),@(ya,yb)cantileverbc(ya,yb,l,F),solinit,options);
Best wishes
Torsten.
Richardson Joseph
on 2 Nov 2015
Torsten
on 2 Nov 2015
You used a command like
xint=linspace(0,30,50);
Sxint=deval(sol,xint);
plot(xint,Sxint(1,:))
?
Best wishes
Torsten.
Richardson Joseph
on 2 Nov 2015
Richardson Joseph
on 3 Nov 2015
Torsten
on 3 Nov 2015
The two y's in the line
yb(4)-l^2*yb(6)+t*l^2*((yb(2))^2*yb(3)+(y(2))^2*y(4))+t*0.5*(yb(2))^3
must either read ya or yb.
Best wishes
Torsten.
Richardson Joseph
on 3 Nov 2015
Torsten
on 3 Nov 2015
Your function "timoshenkoode" has 7 components whereas you only supply 6 components for boundary conditions and initial guesses.
Best wishes
Torsten.
Richardson Joseph
on 3 Nov 2015
Torsten
on 3 Nov 2015
Usually it means that the boundary conditions are insufficient to fix a unique solution.
Best wishes
Torsten.
Categories
Find more on Pulse and Transition Metrics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!