MATLAB: Help with using fsolve

fefsolveimplicit equation

I can not figure out why matlab can not execute my function:
function fx = CSTR(x)
%CSTR
%CO + 0.5 O2 --> CO2
T = x(1);
phi = x(2);
nu_a = -1;
nu_b = -0.5;
nu_c = 1;
%intial reactor conditions
Po = 10^5; %Pa
To = 700; %K
Qo = 0.005; %m^3/s
Rg = 8.314; %Pa.m^3/mol.K
V = 0.3; %m^3
%moles
Ftoto = Po*Qo/(Rg*To); %mol/s






Fao = 0.02*Ftoto; %mol/s
Fbo = 0.5*Fao; %mol/s
Fco = 0; %mol/s
Fdo = 3.5*Fao; %mol/s
Feo = 45*Fao; %mol/s
Fa = Fao*phi; %mol/s
%change in flowrate
Q = ((0.5*phi+49.5)/50)*Qo*(T/To);
%rate equation
k =(1.26*10^10)*exp(-20131/T);
ra = -(0.5^0.25)*(3.5^0.5)*k*((Fao/Q)^1.75)*(phi.^1.25);
%standard enthalpy of reaction at 298K
fH_a = -110.6*10^3; %J/mol




fH_b = 0; %J/mol
fH_c = -393.8*10^3;%J/mol
rH_298 = nu_a*fH_a + nu_b*fH_b + nu_c*fH_c;%J/mol
%heat capacity data
a_a = 28.11; b_a = 0.1672*10^(-2); c_a = 0.5363*10^(-5); d_a = -2.218*10^(-9);
a_b = 25.44; b_b = 1.518*10^(-2); c_b = -0.7144*10^(-5); d_b = 1.310*10^(-9);
a_c = 22.22; b_c = 5.9711*10^(-2); c_c = -3.495*10^(-5); d_c = 7.457*10^(-9);
a_d = 32.19; b_d = 0.1920*10^(-2); c_d = 1.054*10^(-5); d_d = -3.589*10^(-9);
a_e = 28.85; b_e = -0.1569*10^(-2); c_e = 0.8067*10^(-5); d_e = -2.868*10^(-9);
da = nu_a*a_a + nu_b*a_b + nu_c*a_c;
db = nu_a*b_a + nu_b*b_b + nu_c*b_c;
dc = nu_a*c_a + nu_b*c_b + nu_c*c_c;
dd = nu_a*d_a + nu_b*d_b + nu_c*d_c;
%Let g_i(T) = Int_To to T of Cpi)
g_a = a_a(T-To) + (1/2)*b_a*(T^2-To^2) + (1/3)*c_a*(T^3-To^3) + (1/4)*d_a*(T^3-To^3);
g_b = a_b(T-To) + (1/2)*b_b*(T^2-To^2) + (1/3)*c_b*(T^3-To^3) + (1/4)*d_b*(T^3-To^3);
g_c = a_c(T-To) + (1/2)*b_c*(T^2-To^2) + (1/3)*c_c*(T^3-To^3) + (1/4)*d_c*(T^3-To^3);
g_d = a_d(T-To) + (1/2)*b_d*(T^2-To^2) + (1/3)*c_d*(T^3-To^3) + (1/4)*d_d*(T^3-To^3);
g_e = a_e(T-To) + (1/2)*b_e*(T^2-To^2) + (1/3)*c_e*(T^3-To^3) + (1/4)*d_e*(T^3-To^3);
Sum_g_i= Fao*g_a + Fbo*g_b + Fco*g_c + Fdo*g_d + Feo*g_e; %J/s
%enthalpy of reaction
rH = rH_298 + da*(T-298) + db*(1/2)*(T^2-298^2) + dc*(1/3)*(T^3-298^3) + dd*(1/4)*(T^2-298^2); %J/mol
%energy balance and mol balance
fx(1) = Sum_g_i - ra*V*rH;
fx(2) = Fao - Fa + ra*V;
end
I am calling this function using the following:
xguess = [860 0.1];
y = fsolve(@CSTR,xguess);
T = y(1)
phi = y(2)
I get this error:
Error in A8 (line 3)
y =fsolve(@CSTR,xguess);
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
I am unsire why the initial objective function can not be evaluted.
Would therer be a better way to evaulate these implicit and explicit functions?
thank you!

Best Answer

a_a = 28.11;
So a_a is a scalar.
g_a = a_a(T-To) + (1/2)*b_a*(T^2-To^2) + (1/3)*c_a*(T^3-To^3) + (1/4)*d_a*(T^3-To^3);
And there you are indexing the scalar at (T-To)
Similar problem on the lines that follow that.