Filter löschen
Filter löschen

I am recieving an error in creating the solution however it still prints a result.

1 Ansicht (letzte 30 Tage)
clc
clear all
close all
%Homework 7 Question 3
Tin=298; %K
Cp=80; %J/(mol K)
CAin=2000; %mol/m^3
k0=10e-7; %m3/(mol min)
Ea_R=5000; %K
rho=1000; %mol/m^3
CA=linspace(2,2000,61);
xA=(CAin-CA)/CAin;
T_sol=zeros(1,length(CA));
k_sol=zeros(1,length(CA));
tau_sol=zeros(1,length(CA));
DHR=-50000; %J/mol exothermic (gets hot)
for i=1:length(CA)
syms T k tau
eqn1=k==k0*exp((-Ea_R)*((1/T)-(1/Tin)));
eqn2=2*k*(CA(i)^2)==(CAin-CA(i))/tau;
eqn3=k*tau*(CA(i))^2*DHR==rho*Cp*(Tin-T);
solution=solve([eqn1,eqn2,eqn3],[T,k,tau]);
T_sol(i)=double(solution.T);
k_sol(i)=double(solution.k);
tau_sol(i)=double(solution.tau);
end
figure(1)
plot(log10(tau_sol),xA,'-bo');
xlabel('log_{10}(\tau, min)')
ylabel('x_A')

Akzeptierte Antwort

Star Strider
Star Strider am 21 Apr. 2024
Bearbeitet: Star Strider am 21 Apr. 2024
In the last iteration of the loop, the results are all empty. One way to avoid the error is to test for at least one field to be empty:
if ~any(structfun(@isempty, solution))
T_sol(i)=double(solution.T);
k_sol(i)=double(solution.k);
tau_sol(i)=double(solution.tau);
end
Try this —
clc
clear all
close all
%Homework 7 Question 3
Tin=298; %K
Cp=80; %J/(mol K)
CAin=2000; %mol/m^3
k0=10e-7; %m3/(mol min)
Ea_R=5000; %K
rho=1000; %mol/m^3
CA=linspace(2,2000,61);
xA=(CAin-CA)/CAin;
T_sol=zeros(1,length(CA));
k_sol=zeros(1,length(CA));
tau_sol=zeros(1,length(CA));
DHR=-50000; %J/mol exothermic (gets hot)
for i=1:length(CA)
syms T k tau
eqn1=k==k0*exp((-Ea_R)*((1/T)-(1/Tin)));
eqn2=2*k*(CA(i)^2)==(CAin-CA(i))/tau;
eqn3=k*tau*(CA(i))^2*DHR==rho*Cp*(Tin-T);
solution=solve([eqn1,eqn2,eqn3],[T,k,tau]);
if ~any(structfun(@isempty, solution))
T_sol(i)=double(solution.T);
k_sol(i)=double(solution.k);
tau_sol(i)=double(solution.tau);
end
end
figure(1)
plot(log10(tau_sol),xA,'-bo');
xlabel('log_{10}(\tau, min)')
ylabel('x_A')
EDIT — (21 Apr 2024 at 20:14)
Changed if condition to use:
structfun(@isempty, solution)
Code otherwise unchanged.
.

Weitere Antworten (0)

Kategorien

Mehr zu Chemistry finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by