Seeming to have issues with my variables in a boundary value problem

Having issues with my second order differential equation boundary value problem. I think my variables may be off and I am not quite knowledgeable enough to fix my errors on my own. I believe my issue is in how I am (not effectively) separating out into two first order differential equations. Code and Error messages will follow
Solver code:
function dydx=diffus(x,y,c)
dydx=zeros(2,1);
global phi
phi=32;
y(1)=c;
y(2)=c';
dydx(1)=y(2);
dydx(2)=phi^2*(1/441);
function res=diffusbc(ya,yb)
res(1)=ya(1);
res(2)=yb(1)-1;
res=res';
Driver code:
global phi
solinit=bvpinit(linspace(0,1,5),[0 1])
sol=bvp4c(@diffus,@diffusbc,solinit)
x=linspace(0,1);
y=deval(sol,x);
plot(x,y(1,:));
xlabel('radial coordinate')
ylabel('concentration'
And the errors:
>> run_diffus
solinit =
solver: 'bvpinit'
x: [0 0.2500 0.5000 0.7500 1]
y: [2x5 double]
yinit: [0 1]
Error using diffus (line 5)
Not enough input arguments.
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 run_diffus (line 3)
sol=bvp4c(@diffus,@diffusbc,solinit)
Any help would be greatly appreciated!

Answers (1)

sol = bvp4c(odefun,bcfun,solinit) integrates a system of ordinary differential equations of the form
y′ = f(x,y)
but that isn't the form of your function. Your function has three parameters, x, y, and c.
It looks to me as if your "c" is performing the task intended for the "y" parameter. The second parameter essentially gets the value of the current boundary conditions, and I think that's the function you intend for your c.
But there is an alternative explanation, and that is that you are trying to use the f(x,y,p) form of ode45. In order to use that form, solinit.parameters has to be set to the parameter array. The normal method to estimate those values and have solinit.parameters set is to pass a guess at the parameter values as the third argument of bvpinit(). Your ode function would not work unless c was a scalar (possibly complex), so we can see that the [0 1] in your bvpinit call is not intended for that purpose.

Asked:

on 26 Jun 2015

Answered:

on 26 Jun 2015

Community Treasure Hunt

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

Start Hunting!