Solve a system of 3, 2nd order boundary value problems using bvp4c

5 views (last 30 days)
Hello, I want to solve a system of 3 boundary value equations. All three of them are 2nd order. Now I have created my dydx by converting them into 6 ODE's. Since they are huge equations (almost 30 lines) I can give you a gist of them. Baiscally its
eqn1: d2y1/dx +dy1/dx+dy2/dx+dy3/dx+y1+y2+y3+x = const1
eqn2: d2y2/dx +dy1/dx+dy2/dx+dy3/dx+y1+y2+y3+x = const2
eqn3: d2y3/dx +dy1/dx+dy2/dx+dy3/dx+y1+y2+y3+x = const3
Now to put the above equations into bvp4c I converted the above 3 set of equations into 6 set of equations in 1st order ODE's
eqn1: y(2)
eqn2: y(2)+y(4)+y(6)+y(1)+y(3)+ y(5) = const1
eqn3: y(4)
eqn4: y(2)+y(4)+y(6)+y(1)+y(3)+ y(5) = const2
eqn5: y(5)
eqn6: y(2)+y(4)+y(6)+y(1)+y(3)+ y(5) = const3
I know the boundary values of the original 3 equations. They are:
y1(0) = 0.6;
y1(20) = 0;
y2(0) = 0.3;
y2(20) = 0;
y3(0) = 0.005;
y3(20) = 0;
I have written the bcfun function like this:
function res = bcfun(ya, yb)
res = [ya(1); yb(1); ya(2); yb(2); ya(3); yb(3)];
end
And I have written the bvp4c code like this
ya(1) = 101325*0.6;
yb(1) = 0;
ya(2) = 101325*0.3;
yb(2) = 0;
ya(3) = 101325*50e-06;
yb(3) = 0;
solinit = bvpinit(linspace(0,4,5),[1 0], linspace(0,4,5),[1 0], linspace(0,4,5),[1 0]);
sol = bvp4c(@myodesubfunc, @bcfun, solinit);
xint = linspace(1e-20, 20e-6, 50)
yint = deval(sol, xint)
After running this I get an error
??? Error using ==> myodesubfunc
Too many input arguments.
Error in ==> bvparguments at 106
testODE = ode(x1,y1,odeExtras{:});
Error in ==> bvp4c at 130
[n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] = ...
Error in ==> bvp at 28
sol = bvp4c(@myodesubfunc, @bcfun, solinit);
If you can help me with the syntax ( just a small part of it) that will great
Thanks, Nitin Nair

Answers (4)

Walter Roberson
Walter Roberson on 26 Jan 2012
Since it is the myodesubfunc function that is being complained about, we need to see the code for myodesubfunc .

Nitin
Nitin on 26 Jan 2012
For myodesubfunc I wrote the code like this
function dydx = myodesubfunc(x,y)
dydx = [ the six equations written above with proper syntax];
end

Walter Roberson
Walter Roberson on 26 Jan 2012
You are passing more than two values to bvpinit(). There is no bvpinit() syntax defined for six parameters, so possibly anything beyond the third parameter is being ignored. The three-parameter form of bvpinit() initializes the 'parameters' field of solinit. Then in the bvp4c() call, if the 'parameters' field of solinit is defined, then your ode function must accept 3 arguments, but your ode function myodesubfunc only accepts two arguments, leading to the error about two many input arguments.
I would suspect your bvpinit() call is incorrect.

eh
eh on 29 Nov 2013
Hi I want to solve system of coupler ODEs in ode45 my boundary condition :: Some conditions are initially And others in end . can you helpe mi to enter boundary condition???

Products

Community Treasure Hunt

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

Start Hunting!