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)
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

Torsten
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
Richardson Joseph
Richardson Joseph on 2 Nov 2015
ok,it is as below....thanks
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=zeros(4,1);
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));
[ 4*x^2*exp(x)*(x - 30)^3 + x^2*exp(x)*(x - 30)^4 + 2*x*exp(x)*(x - 30)^4, 24*exp(x)*(x - 30)^3 + 6*exp(x)*(x - 30)^4 + 12*x^2*exp(x)*(2*x - 60) + 36*x^2*exp(x)*(x - 30)^2 + 12*x^2*exp(x)*(x - 30)^3 + x^2*exp(x)*(x - 30)^4 + 72*x*exp(x)*(x - 30)^2 + 48*x*exp(x)*(x - 30)^3 + 6*x*exp(x)*(x - 30)^4];
[ 4*x^2*exp(x)*(x - 30)^3 + x^2*exp(x)*(x - 30)^4 + 2*x*exp(x)*(x - 30)^4, 24*exp(x)*(x - 30)^3 + 6*exp(x)*(x - 30)^4 + 12*x^2*exp(x)*(2*x - 60) + 36*x^2*exp(x)*(x - 30)^2 + 12*x^2*exp(x)*(x - 30)^3 + x^2*exp(x)*(x - 30)^4 + 72*x*exp(x)*(x - 30)^2 + 48*x*exp(x)*(x - 30)^3 + 6*x*exp(x)*(x - 30)^4, 24*x^2*exp(x) + 144*exp(x)*(x - 30)^2 + 96*exp(x)*(x - 30)^3 + 12*exp(x)*(x - 30)^4 + 48*x^2*exp(x)*(2*x - 60) + 72*x^2*exp(x)*(x - 30)^2 + 16*x^2*exp(x)*(x - 30)^3 + x^2*exp(x)*(x - 30)^4 + 96*x*exp(x)*(2*x - 60) + 288*x*exp(x)*(x - 30)^2 + 96*x*exp(x)*(x - 30)^3 + 8*x*exp(x)*(x - 30)^4]];

Sign in to comment.

More Answers (1)

Torsten
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
Richardson Joseph on 3 Nov 2015
I changed the components number to "6" but still the same error of "singular jacobian".Is it related to wrong initial guess?
Thanks

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!