Still missing input arguments and not familiar enough to write all data in matrices
조회 수: 2 (최근 30일)
이전 댓글 표시
The script is made to solve multiple steady state conditions of a tank reactor. the conditions are dependent on temperature T and feed inlet Ca0 and Cb0 The script i currently use is:
function G = tankreactor(x)
T = [298:1:315];
k1 = zeros(1,18);
k2 = k1; k3 = k1;
Ea1 = 24744;
Ea2 = 50435;
Ea3 = 35495;
R = 8.314;
k1 = 456.6.*exp(-Ea1./(R.*T))
k2 = 10395860.*exp(-Ea2./(R.*T))
k3 = 200.*exp(-Ea3./(R.*T))
eta = [0.1 0.2 0.5 1 2 5 10];
V = 1000 flow = 0.1;
Ca0 = 0.5;
Cb0 = eta * Ca0;
Cc0 = 0
Cd0 = 0
Ce0 = 0
f1 = flow*(Ca0 - x(1))+V*(-k1*x(1)*x(2)-k3*x(1));
f2 = flow*(Cb0 - x(2))+V*(-k1*x(1)*x(2)-k2*x(2)*x(3));
f3 = flow*(Cc0 - x(3))+V*(k1*x(1)*x(2)-k2*x(2)*x(3));
f4 = flow*(Cd0 - x(4))+V*(k2*x(2)*x(3));
f5 = flow*(Ce0 - x(5))+V*(k3*x(1));
G = [f1;f2;f3;f4;f5];
end
function [x] = solvex4b()
x0 = [0.1 0.2 0.3 0.4 0.1];
options=optimset('Display','iter');
x = fsolve(@tankreactor,x0,options);
end
The output of the fsolve needs to be a matrix where the x values are written as function of T and eta. Which i want to plot. This is the part where i can't get my hand on: the error i currently have is missing of input arguments, i still need to include some loops for the data writing aswell. I hope anyone has an idea.
Thanks in advance!
Frenk
답변 (1개)
Star Strider
2014년 9월 14일
편집: Star Strider
2014년 9월 14일
I deleted the ‘solvex4b’ function definition (and its terminating ‘end’) because there is no need for it.
After I vectorised your code, the problem I have in ‘tankreactor’ is this line:
f2 = flow*(Cb0 - x(2))+V*(-k1.*x(1).*x(2)-k2.*x(2).*x(3));
because ‘Cb0’ is a (1x7) vector, so the ‘f2’ line throws the:
Error using +
Matrix dimensions must agree.
error.
I’ll let you sort that out. You may want to supply each element of ‘eta’ as an argument, pass different values of it to your function in a loop, then optimise for various values of it in each loop iteration. That would be my approach.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!