Solving arrays in an equation to a variable

syms T p
pfun=fun_EthanolDampfdruck(T);
Unrecognized function or variable 'fun_EthanolDampfdruck'.
TSiede=vpasolve(pfun==1.01325,T,300); %Boilingtemperature of Ethanol at 1.013 bar
fprintf('The vapor pressure of Ethanol is %4.2f °C at a system pressure of 1.013bar ',TSiede-273.15)
R=8.314; %universal Gas constant J/(mol*K)
q=38720; %Heat of vaporization in J/mol at 78.27°C and 1.013bar
p=[1.013; 1.05; 1.08; 1.013; 1.05; 1.08; 1.013; 1.05; 1.08; 1.013; 1.05; 1.08; 1.013; 1.05; 1.08; 1.013; 1.05; 1.08; 1.013; 1.05; 1.08];
TS=zeros(1,length(p));
for i=1:length(p)
TS(i)=vpasolve(pfun==p(i),T,300);
end
x=[0.1; 0.1; 0.1; 0.15; 0.15; 0.15; 0.18; 0.18; 0.18; 0.20; 0.20; 0.20; 0.21; 0.21; 0.21; 0.22; 0.22; 0.22; 0.23; 0.23; 0.23]; %Weightfraction of A in Ethanol-Solution
T=[81.62; 82.53; 83.25; 84.98; 85.92; 86.63; 87.84; 88.75; 89.45; 90.07; 90.88; 91.6; 91.24; 92.04; 92.74; 92.5; 93.33; 94.03; 93.72; 94.52; 95.23]; %Temperature in °C
T=T+273.15; %Temperature in K
for i=1:length(T)
px(i)=fun_EthanolDampfdruck(T(i));
end
px;
dp=px-p'; %Delta Partialpressure of the solution to pure Ethanol
dTb=TS'-T % Delta Boiltingtemperature of the Solution to pure Ethanol
syms m
for i=length(dTb)
m(i)=solve(dTb(i)==m*(1-x(i))/x(i)*R*T(i)^2/q,m) % Equation is dTb=m*(1-x)/x*R*T^2/q
end
With my Code m shows me the following image with only one solution at m(1,21). dTb,x,T are all 21x1. How can i get m for dTb/x/T(1:21). If there is a basic failure in my Script please let me know, im new to matlab :)

5 Comments

Torsten
Torsten on 26 Jun 2023
Edited: Torsten on 26 Jun 2023
Don't name the symbolic variable and the array in which you save the solution both "m".
i changed
m(i)=solve(dTb(i)==m*(1-x(i))/x(i)*R*T(i)^2/q,m)
to
l(i)=solve(dTb(i)==m*(1-x(i))/x(i)*R*T(i)^2/q,m)
And the result is almost the same
We need to know the array dTb.
@Kevin, could you share the function fun_EthanolDampfdruck?
Without it, we don't know the values obtained, as @Torsten points above, and it is difficult to suggest anything.
function y=fun_EthanolDampfdruck(T) %Temperatur in °C
A=-8.33801;
B=0.08719;
C=-3.30578;
D=-0.25986;
Tc=513.90; %kritische Temperatur in Kelvin
F=1-T/Tc;
pc=61.48; %kritscher Druck in bar
y=exp(Tc/T*(A*F+B*F^1.5+C*F^2.5+D*F^5))*pc;
end
The function works without Problems.
dTb is shown in the following picture

Sign in to comment.

 Accepted Answer

Quite a minor mistake.
The loop index is of the last for loop is only length(dTb), that's why only the last value is obtained as you mentioned earlier in the comments.
for i=length(dTb)
% ^ see here
l(i)=solve(dTb(i)==m*(1-x(i))/x(i)*R*T(i)^2/q,m); % Equation is dTb=m*(1-x)/x)*R*T^2/q
end
It should be 1:length(dTb)
for i=1:length(dTb)
% ^ corrected
l(i)=solve(dTb(i)==m*(1-x(i))/x(i)*R*T(i)^2/q,m); % Equation is dTb=m*(1-x)/x)*R*T^2/q
end
Your code works after the correction.
Use double if you want to convert the symbolic values of the output variable to numeric values.

More Answers (0)

Categories

Products

Release

R2022b

Asked:

on 26 Jun 2023

Commented:

on 27 Jun 2023

Community Treasure Hunt

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

Start Hunting!