So I have the task to solve a system of equations over a range of temperatures and a range of volumes. From this, I am supposed to make surface plots of my results. The problem is, I can only get one of my loops to output it's proper range of data, because I do not know how to get matlab to store the data from the loops in a matrix, instead of creating one long vector. If anyone could help, that would be wonderful. Thanks
%this first section is just constants the equations need to run
mdot=1;
A=2;
E=1;
ndot=2;
kb=0.4;
knb=0.03;
ktb=0.005;
kc=0.05;
knc=0.045;
ktc=0.03;
KMB=(knb+ktb)/kb;
KMC=(knc+ktc)/kc;
v=20;
x1=[];
x2=[];
x3=[];
x4=[];
x5=[];
xa=[];
xb=[];
xc=[];
xd=[];
xf=[];
xg=[];
xUU=[];
DH1=9000;
DG1=-10000;
DH2=-15000;
DG2=500;
DH3=30000;
DG3=500;
P=0.5;
R=8.314;
spaces=24;
n=((500-20)/spaces)+1;
J=linspace(20,500,n);
T=273
for i=1:1
Lk1=(-1/R)*(((DG1-DH1)/298)+(DH1/T));
k1=exp(Lk1)
Lk2=(-1/R)*(((DG2-DH2)/298)+(DH2/T));
k2=exp(Lk2)
Lk3=(-1/R)*(((DG3-DH3)/298)+(DH3/T));
k3=exp(Lk3)
for w=1:length(J)
fun=@(x)ndot-x-(ktb*E*x/(x+KMB*mdot))*v-(ktc*E*x/(x+KMC*mdot))*v;
x0=1;
[x]=fsolve(fun,x0);
v=v+spaces;
xtwo=(ktb*E*x/(x+KMB*mdot))*v;
xthree=(ktc*E*x/(x+KMC*mdot))*v;
xfour=[x]+xtwo+xthree;
Eqsys=@(y)[(k1*(y(1)^2)*y(2)*y(3))-((y(4)^3)),
(k2*y(1)*y(2))-(y(3)*(y(5)^3)*(P^2)),
(k3*P*y(1)*y(2))-y(6),
([x]-2*y(7)-y(8)-y(9)-y(1)),
(xtwo-y(7)-y(8)-y(2)),
(xthree-y(7)+y(8)-y(9)-y(3)),
((3*y(7))-y(4)),
((3*y(8))-y(5)),
(y(9)-y(6))];
b=[1,1,1,1,1,1,1,1,1];
q=fsolve(Eqsys,b);
x1=[x1;[x]];
x2=[x2 xtwo];
x3=[x3 xthree];
x4=[x4 xfour];
x5=[x5;q];
xa=[xa;q(:,1)];
xb=[xb;q(:,2)];
xc=[xc;q(:,3)];
xd=[xd;q(:,4)];
xf=[xf;q(:,5)];
xg=[xg;q(:,6)];
end
T=T+(150/(n));
end
% so if anyone can get the values to run from v=20 to 500 and T=273 to 423, that would be wonderful. Thanks
2 Comments
KSSV (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/364591-how-do-i-store-data-in-multiple-loops#comment_499975
Scott Powers (view profile)
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/364591-how-do-i-store-data-in-multiple-loops#comment_499983
Sign in to comment.