Info

This question is closed. Reopen it to edit or answer.

Help with error!! attempted to access x(1); index out of bounds because numel(x) =0.

1 view (last 30 days)
Apologies for the sloppiness
I cannot figure out where I have gone wrong. I am trying to solve a boundary problem using bvp4c.
function project1run
solinit = bvpinit(linspace(3,9,0.2),[-1,1]);
sol = bvp4c(@project1,@project1bc,solinit);
plot (sol.x, sol.y(1,:),'-r')
%part 1 values
%pH = 9
Ckcl = 10
Rp = 40e-9
%if else for values of Ci0
if pH >7
C10 = 10^(-pH+3);
C20 = Ckcl+10^(-pH+3)-10^(-(14-pH)+3);
C30 = Ckcl;
C40 = 10^(-(14-pH)+3);
else
C10 = 10^(-pH+3);
C20 = Ckcl;
C30 = Ckcl+10^(-pH+3);
C40 = 10^(-(14-pH)+3);
end
%variables
epsilonf = 7.08e-10;
F = 96490;
R = 8.31;
T = 300;
z1 = 1;
z2 = 1;
z3 = -1;
z4 = -1;
lambdaD = sqrt(epsilonf*R*T/(F^2*...
(z1^2*C10+z2^2*C20+z3^2*C30+z4^2*C40)));
r = Rp+5*lambdaD;
%variable for summation
E = z1^2*C10*exp(-z1*F/(R*T))+z2^2*C20*exp(-z2*F/(R*T))...
+z3^2*C30*exp(-z3*F/(R*T))+z4^2*C40*exp(-z4*F/(R*T))
%for sigma equation
Ntotal = 1.3285e-5;
Ka = 10^(-7.6+3);
Kb = 10^(-1.9+3);
%phis = 1;
Hs = C10*exp(-F*phis/(R*T));
sigma = -F*Ntotal*((Ka-Kb*Hs^2)/(Ka+Hs+Kb*Hs^2))
%equations for bvp function
function res = project1bc(ya,yb)
pHhigh = 9;
pHlow = 3;
res = [ya(1) yb(2)+sigma/epsilonf]
end
function dydx = project1(x,y)
dphidr = [y(2)
-(1/r)*y(2)-((1/epsilonf)*F*E*y(1))]
end
end
  1 Comment
Walter Roberson
Walter Roberson on 1 Oct 2013
The only place your code mentions "x" is in
function dydx = project1(x,y)
and then you do not use "x" in the body of that function. Therefor the error must be in something you called from the above code. Please show the complete error message you get, everything that shows up in red when you get the error.

Answers (0)

Community Treasure Hunt

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

Start Hunting!