BVP4C: The derivative function ODEFUN should return a column vector of length 10

19 views (last 30 days)
Hello
I have to resolve an ODE with boundary conditions, so I had to use the function bvp4c.
xa=-c;
xb=c;
solinit=bvpinit(linspace(xa,xb,20),[1 1 1 1 1 1 1 1 1 1]);
sol=bvp4c(@(x,g)bvp4ode_g(x,g,GAMMA,B,z,y1,y2,y3,y4,y5,y6,y7,y8,y9),@(ga,gb)bvp4bc_g(ga,gb,a,a1,a2,K,nu1,nu2),solinit);
xint=linspace(xa,xb,100);
Sxint=deval(sol,xint);
function bc=bvp4bc_g(ga,gb,a,a1,a2,K,nu1,nu2)
bc=[ga(9)-1 ga(3) ga(4)-(3*a/a1)*ga(10) ga(8)+ga(7)*sqrt(2)*(K(2,1))^(1/4)+ga(6)*(K(2,1))^(1/2)-(3*a/a2)*ga(10) ga(7)+ga(6)*sqrt(2)*(K(2,1))^(1/4)+ga(5)*(K(2,1))^(1/2)+(2*sqrt(3)*nu2*(1-(nu2)^2)^(-1/2))*a/a2 gb(9)+1 gb(7) gb(8)-(3*a/a2)*gb(10) gb(4)+gb(3)*sqrt(2)*(K(1,1))^(1/4)+gb(2)*(K(1,1))^(1/2)-(3*a/a1)*gb(10) gb(3)+gb(2)*sqrt(2)*(K(1,1))^(1/4)+gb(1)*(K(1,1))^(1/2)+(2*sqrt(3)*nu1*(1-(nu1)^2)^(-1/2))*a/a1];
end
function dydx=bvp4ode_g(x,g,GAMMA,B,z,y1,y2,y3,y4,y5,y6,y7,y8,y9)
dydx=[g(2) g(3) g(4) (y1+y3*y9)*g(1)+(y3*B(1,1))*g(3)+GAMMA(1,2)*y3*y8*g(5)+(y3*B(2,1))*g(7)+(y2+y3*y7)*g(9)+y3*z-y2 g(6) g(7) g(8) (GAMMA(2,1)+y6*y9)*g(1)+(y6*B(1,1))*g(3)+(y4+y6*y8)*g(5)+(y6*B(2,1))*g(7)+(y5+y6*y7)*g(9)+y6*z+y5 g(10) y9*g(1)+B(1,1)*g(2)+y8*g(5)+B(2,1)*g(7)+y3*g(9)+z];
endfunction dydx=bvp4ode_g(x,g,GAMMA,B,z,y1,y2,y3,y4,y5,y6,y7,y8,y9)
dydx=[g(2) g(3) g(4) (y1+y3*y9)*g(1)+(y3*B(1,1))*g(3)+GAMMA(1,2)*y3*y8*g(5)+(y3*B(2,1))*g(7)+(y2+y3*y7)*g(9)+y3*z-y2 g(6) g(7) g(8) (GAMMA(2,1)+y6*y9)*g(1)+(y6*B(1,1))*g(3)+(y4+y6*y8)*g(5)+(y6*B(2,1))*g(7)+(y5+y6*y7)*g(9)+y6*z+y5 g(10) y9*g(1)+B(1,1)*g(2)+y8*g(5)+B(2,1)*g(7)+y3*g(9)+z];
end
But I get this errors:
Error using bvparguments (line 109)
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT):
The derivative function ODEFUN should return a column vector of length 10.
Error in bvp4c (line 130)
[n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] = ...
Error in LR (line 69)
sol=bvp4c(@(x,g)bvp4ode_g(x,g,GAMMA,B,z,y1,y2,y3,y4,y5,y6,y7,y8,y9),@(ga,gb)bvp4bc_g(ga,gb,a,a1,a2,K,nu1,nu2),solinit);
>>
Thanks for your help.
  1 Comment
Torsten
Torsten on 3 Sep 2015
Your vector of initial conditions has length 10, but you supply derivatives only for 9 equations ...
And the vectors you supply should be column vectors, not row vectors ...
Best wishes
Torsten.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 31 Aug 2015
You appear to be returning row vectors instead of column vectors.
  4 Comments
Walter Roberson
Walter Roberson on 31 Aug 2015
For example,
function bc=bvp4bc_g(ga,gb,a,a1,a2,K,nu1,nu2)
bc=[ga(9)-1 ga(3) ga(4)-(3*a/a1)*ga(10) ga(8)+ga(7)*sqrt(2)*(K(2,1))^(1/4)+ga(6)*(K(2,1))^(1/2)-(3*a/a2)*ga(10) ga(7)+ga(6)*sqrt(2)*(K(2,1))^(1/4)+ga(5)*(K(2,1))^(1/2)+(2*sqrt(3)*nu2*(1-(nu2)^2)^(-1/2))*a/a2 gb(9)+1 gb(7) gb(8)-(3*a/a2)*gb(10) gb(4)+gb(3)*sqrt(2)*(K(1,1))^(1/4)+gb(2)*(K(1,1))^(1/2)-(3*a/a1)*gb(10) gb(3)+gb(2)*sqrt(2)*(K(1,1))^(1/4)+gb(1)*(K(1,1))^(1/2)+(2*sqrt(3)*nu1*(1-(nu1)^2)^(-1/2))*a/a1];
bc = bc(:); %make it into column vector
end

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!