From: Rob on 22 Dec 2008 09:03 Can anybody help me with the following problem: CODE function test2 clc;clear;close all; z=2; solinit = bvpinit(linspace(0,z,50),ones(7,1)); sol = bvp4c(@ode,@bc,solinit); function dydx = ode(x,y); K = 100; q = 5; dydx = [ y(2) y(3) (1/K)*y(4) q-(c*y(1)) y(6) y(7) (1/K)*y(8) -c*y(5) ]; end function res = bc(ya,yb) res = [ya(2) ya(4) yb(1) - yb(5) yb(2) - yb(6) yb(3) - yb(7) yb(4) - yb(8) ]; end end When I run this, it doesn't work because: ??? Attempted to access yb(8); index out of bounds because numel(yb)=7. But when I use one(8,1) in solinit: ??? Error using ==> bvp4c at 194 The boundary condition function should return a column vector of length 8 How can I solve this problem?
From: Rob on 22 Dec 2008 11:40 I've made some mistakes, because I defined not all bc. My new code is: function test2v2 clc;clear;close all; xinit = [0, 0.25, 0.5, 1, 1, 1.25, 1.5, 1.75, 2]; yinit = ones(8,1); solinit = bvpinit(xinit,yinit); sol = bvp4c(@ode,@bc,solinit); function dydx = ode(x,y,region); c = 0.3; K = 100; q = 5; dydx = [ y(2) y(3) (1/K)*y(4) q-(c*y(1)) y(6) y(7) (1/K)*y(8) -c*y(5) ]; end function res = bc(YL,YR) res = [YL(2,1) YL(4,1) YL(1,2) - YR(1,1) YL(2,2) - YR(5,1) YL(3,2) - YR(6,1) YL(4,2) - YR(8,1) YR(1,end) YR(2,end) ]; end end But still this doesn't work: ??? Error using ==> bvparguments at 132 Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT): The boundary condition function BCFUN should return a column vector of length 16. Error in ==> bvp4c at 120 [n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] = ... Error in ==> test2v2 at 9 sol = bvp4c(@ode,@bc,solinit)
|
Pages: 1 Prev: fprintf output truncation Next: about matlab function defined in a .m file |