using fsolve with matrix
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Rodrigo Blas
il 7 Mag 2020
Risposto: Walter Roberson
il 7 Mag 2020
I would like to calculate xeq using fzero
xeq should be a vector.
T and Y is a vector.
function ydot=Zazarian_f_5(~,x)
X=x(1); y=x(2); T=x(3);
% given & calculation
T0=325;
Ta=300;
Fa0=5;
Fb0=10;
Fi0=10;
Ca0=0.2;
Cp_a=20;
Cp_b=20;
Cp_c=20;
Cp_i=18;
alpha=0.00015;
k1=0.0002;
Ua=320;
pb=1400;
e=25000;
mc=18;
thb=2;
thi=2;
delta_Hrx=-20000;
Cp_cool=18;
r=1.987;
kc1=1000;
%calculation
k2=k1*exp((e/r)*((1/300)-(1/T)));
Kc2=kc1*exp((-delta_Hrx/r)*((1/305)-(1/T)));
CA=Ca0*(1-X)*y*(T0/T);
CB=Ca0*(1-X)*y*(T0/T);
CC=Ca0*(1+2*X)*X*y*(T0/T);
Ci=2*Ca0*y*(T0/T);
ra=-k2*((CA*CB)-((CC^2)/Kc2));
ydot(1)=(-ra)/(Fa0);
ydot(2)=(-alpha/(2*y))*(T/T0);
ydot(3)=(-delta_Hrx*ra)/(Fa0*(Cp_a+(thb*Cp_b)+(thi*Cp_i)));
ydot = ydot';
end
%%Script:
clear all
clc
y0=[0 1 325]; % why a initial pressure drop of 1
W=[0 1000];
r=1.987;
kc1=1000;
Tkc1 = 305;
T0=325;
delta_Hrx=-20000;
% X vs W
[t,y]=ode45(@Zazarian_f_5, W, y0);
Teq = y(:,3);
Y=y(:,2);
X = y(:,1);
T = T0 + (X*delta_Hrx)/(60);
% Temperature vs W
figure
plot(t, T);
%using other guys
%plot(t, y(:,3));
xlabel('catalyst weight in kg');
ylabel('Temperature');
legend('T');
title('Temperature');
% step 2 Kc -- equilibrium constant equation at a t
xo=0;
%Kc2=kc1*exp((-delta_Hrx/r)*((1/305)-(1/T)));
Ca0=0.2;
KC=kc1*exp((-delta_Hrx/r)*((1/Tkc1)-(1./Teq)));
CA=@(xeq)Ca0*(1-xeq).*Y*(T0./Teq);
CB=@(xeq)Ca0.*(1-xeq).*Y.*(T0./Teq);
CC=@(xeq)Ca0*(1+2.*xeq).*Y.*(T0./Teq);
myfun=@(xeq) CC(xeq).^2./(CA(xeq).*CB(xeq))-KC;
XEQ=fzero(myfun,xo);
Error using fzero (line 306)
FZERO cannot continue because user-supplied function_handle ==> @(xeq)CC(xeq).^2./(CA(xeq).*CB(xeq))-KC failed with the
error below.
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of
rows in the second matrix. To perform elementwise multiplication, use '.*'.
Error in zzz (line 41)
XEQ=fzero(myfun,xo);
>>
0 Commenti
Risposta accettata
Walter Roberson
il 7 Mag 2020
fzero() can only be used for functions of one variable that return scalar results.
You will need to switch to fsolve() instead of fzero()
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!