Info
This question is closed. Reopen it to edit or answer.
Need some help with equation error, please.
2 views (last 30 days)
Show older comments
I've set up the following two files to run an electrical potential problem and one of the variables that I'm using involves using a bvp4c boundary conditions. I have attached my project sheet for a little background on the problem.
If someone could show me why its incorrect and what I can do to repair it, I would greatly appreciate it. I'm sure that if and when it is corrected there may be other errors that arise but I guess I'll get to fixin' when that time comes.
Error:
Undefined function 'ya' for input arguments of type 'double'.
Error in MAE340_P1 (line 14)
Hs = c10*exp((-F/R*T)*ya(2));
Main Function:
function main
global Ckcl Rp pph pH
Ckcl = 10;
Rp = 40e-9;
pph = 3:0.2:9;
for i = 1:length(pph)
pH = pph(i);
sigma_pH(i)= MAE340_P1(Ckcl,pH,Rp)
end
plot(pph,sigma_ph)
Ckcl = 1:1:100;
pH = 6;
Rp = 40e-9;
for i = 1:length(Ckcl)
Ckcl = Ckcl(i) +1;
sigma_Ckcl(i) = MAE340_P1(Ckcl,pH,Rp)
end
plot(Ckcl,sigma_Ckcl)
Ckcl = 10;
pH = 6;
Rp = 10-e8:10e-9:10e-7;
for i = 1:length(Rp)
sigma_Rp = MAE340_P1(Ckcl,pH,Rp)
end
plot(Rp,sigma_Rp)
2nd Function:
function sigma_1 = MAE340_P1(Ckcl,pH,Rp)
global N F R T c10 c20 c30 c40 z1 z2 z3 z4 ka kb Ef lambda rlow rhigh sigma_2
z1 = 1;
z2 = 1;
z3 = -1;
z4 = -1;
T = 300;
R = 8.314;
F = 96490;
Ef = 7.08e-10;
N = 1.3285e-5;
ka = 10^-4.6;
kb = 10^2.9;
Hs = c10*exp((-F*ya(2)/R*T));
sigma_2 = -F*N*((ka-kb*Hs^2)/(ka+Hs+kb*Hs^2));
lambda = sqrt((Ef*R*T)/( (F^2)*(z1^2*c10+z2^2*c20+z3^2*c30+z4^2*c40)));
rlow = Rp;
rhigh =Rp+5*lambda;
if pH>= 7
c10 = 10^(-pH+3);
c20 = Ckcl;
c30 = Ckcl + 10^(-pH+3) - 10^-(14-pH)+3;
c40 = 10^-(14-pH)+3;
else
c10 = 10^(-pH+3);
c20 = Ckcl + 10^(-pH+3) - 10^-(14-pH)+3;
c30 = Ckcl;
c40 = 10^-(14-pH)+3;
end
solinit = bvpinit(linspace(rlow,rhigh,100),[1 0]);
sol = bvp4c(@bvp4ode,@bvp4bc,solinit);
xint = linspace(rlow,rhigh,20);
plot(xint,sxint(1,:));
function dydr = bvp4ode(r,y)
global N F R T c10 c20 c30 c40 z1 z2 z3 z4 ka kb Ef lambda rlow rhigh sigma_2 Rp
dydr = [y(2) -(1/r)*y(2)-(1/Ef)*F*(z1*c10^((z1*F)/(R*T))*y(1)+z2*c20^((z2*F)/(R*T))*y(1)+z3*c30^((z3*F)/(R*T))*y(1)+z4*c40^((z4*F)/(R*T))*y(1))];
function res = bvp4bc(ya,yb)
global N F R T c10 c20 c30 c40 z1 z2 z3 z4 ka kb Ef lambda rlow rhigh sigma_2 Rp
res = [ya(2)+(sigma_2/Ef) yb(1)];
0 Comments
Answers (1)
Cedric
on 4 Oct 2013
Edited: Cedric
on 4 Oct 2013
As the error message says, you are using variable ya in function MAE340_P1 on line 14:
Hs = c10*exp((-F*ya(2)/R*T));
and it is defined nowhere before this line. The only place where you seem to define such a variable, is as a first input parameter of function bvp4bc.
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!