Undefined function or variable 'x'

2 views (last 30 days)
maroubi maria
maroubi maria on 11 Mar 2016
Edited: per isakson on 11 Mar 2016
i have these 3 functions,but there is a problem when i run them
Undefined function or variable 'x'
Error in ==> elec at 74
F=spring(x)
i can't find the mistake.please help
function [A,i,V,W,I,m5,m6,w5,w6,C5,C25,H5,N4,O4,N5,H6,O5,N6,O6,C6,C26,ksi]=elec(fi,m3,C3,C23,w3,H3,N3,O3,m4,C4,C24,w4,H4,F,uf,R,TC,PC)
%
m3=967.18; %kmol/h
w3=11465;
C3=350.83;
C23=1742;
H3=8020.5;
N3=540;
O3=0 ;
m4=0 ;
C4=0 ;
C24=0 ;
w4=0;
H4=0 ; %kmol/h
fi=10;
uf=50;
F=96485.33; %A*s/mol
R=8.314; %J/molK
TC=1073; %K
TAN=833;
TKAF=973;
PC=2 ; %atm
ksi=(uf/100)*H3*0.28; %mol/s
O4=(fi*23085.94)/4.76;
N4=(fi*23085.94)/1.26;
O6=O4+0.5*ksi;
N6=N4;
H6=H4;
w6=w4;
C26=C24;
C6=C4;
m6=m4;
O5=O3;
N5=N3;
H5=H3+ksi;
w5=w3-ksi;
C25=C23;
C5=C3;
m5=m3;
reuma3=m3+w3+C3+H3+C23+O3+N3;
reuma4=m4+w4+C4+H4+C24+O4+N4 ;
reuma5=m5+w5+C5+H5+C25+O5+N5 ;
reuma6=m6+w6+C6+H6+C26+O6+N6 ;
y3=[m3/reuma3 w3/reuma3 C3/reuma3 H3/reuma3 C23/reuma3 O3/reuma3 N3/reuma3];
y4=[m4/reuma4 w4/reuma4 C4/reuma4 H4/reuma4 C24/reuma4 O4/reuma4 N4/reuma4];
y5=[m5/reuma5 w5/reuma5 C5/reuma5 H5/reuma5 C25/reuma5 O5/reuma5 N5/reuma5];
y6=[m6/reuma6 w6/reuma6 C6/reuma6 H6/reuma6 C26/reuma6 O6/reuma6 N6/reuma6];
%
W=reuma3*enthalpy(y3,TAN)+reuma4*enthalpy(y4,TKAF)-reuma5*enthalpy(y5,TC)-reuma6*enthalpy(y6,TC); %isozigioenergeias
%
I=ksi*2*F;
V=W/I;
F=96485.33; %A*s/mol
R=8.314; %J/molK
TC=1073; %K
i0=1; %A/cm2
iL=4; %A/cm2
PC=2; %atm
Rw=0.1;
PH=(H5/reuma5)*PC;
PO=(O6/reuma6)*PC;
Pw=(w5/reuma5)*PC;
f=(R*TC)/F;
F=spring(x)
A=I/i;
end
function h=enthalpy(y,T)
%
% A user defined function to calculate
% the specific enthalpy of the gases of
% the SR/SOFC/UB systems
%
% Input arguments : y = vector of mole fractions of the gas mixture [-]
% T = temperature [K]
% Output argument : h = specific enthalpy of gas mixture [kJ/kmol]
% Components
% 1 2 3 4 5 6 7
% CH4 H2O CO H2 CO2 O2 N2
h=0;
href=[-74870 -241830 -110530 0 -393520 0 0]; % enthalpy of formation of the ideal das at 298.15 K in [kJ/kmol]
Tref=298.15; % temperature at which enthapy equals enthalpy of formation of ig
% cp = C + B * T + A * T^2
% constants A,B,C are fitted values to raw data from NIST Chemistry webbook
%
A=[0 0 2.5359e-6 1.5807e-6 -2.2051e-05 -7.1534e-06 0 ];
B=[0.05346 0.01133 0.00300006 -0.00050303 0.05228 0.016494 0.0053629];
C=[19.676 29.704 27.774 29.058 23.853 24.991 27.237];
for j=1:7
h= h + y(j) * ((A(j)/3) * (T^3-Tref^3) + (B(j)/2) * (T^2-Tref^2) + C(j) * (T-Tref) + href(j));
end
%
%
function F=spring(x)
F(1)=x(1)-Rw*x(2); %x(1)=nw,x(2)=i
F(2)=x(3)-2*f*asihn(x(2)/(2*i0)); %x(3)=nact
F(3)=x(4)-(f/2)*log(iL/(iL-x(2))); %x(4)=nconc
F(4)=x(5)-x(6)+(x(1)+x(3)+x(4)); %x(5)=V,x(6)=E
F(5)=x(6)-1.2528-2.307*e-4*TC+(f/2)*log((PH*sqrt(PO))/Pw);
fun=@spring;
x0=[0,0,0,0,0,0];
x=fsolve(fun,x0);
nw=x(1);
i=x(2);
nact=x(3);
nconc=x(4);
V=x(5);
E=x(6);
end

Answers (1)

Star Strider
Star Strider on 11 Mar 2016
You never define ‘x’ anywhere in your code. You have to figure out what vector you want to pass as an argument to your ‘spring’ function. (It doesn’t have to be called ‘x’.)
Also, assigning the ‘spring’ function call to ‘F’ is going to overwrite the constant you have assigned to ‘F’ several lines before that.

Categories

Find more on Thermal Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!