Error converting from sym to double: Unable to convert expression into double array
3 views (last 30 days)
Show older comments
Kate Kirwan
on 17 Apr 2021
Commented: Star Strider
on 18 Apr 2021
Hi,
I am having a problem with the syms function in matlab and I was wondering if anyone could help. The help would be greatly appreciated.
The code is to caclulate the bubblepoint of a mixture which contains n components.
The beginning of the code can be seen below. The last line is where the error :Error converting from sym to double: Unable to convert expression into double array
occurs.
CODE:
P_total = input('Please enter the total pressure in mm Hg: \n');
n = input('Please enter the number of components:\n');
x = zeros(1, n); % Liquid phase mole fractions
y = zeros(1, n); % Vapour phase mole fractions
load Antoine_coefficients.txt % reading in the file which contains the Antoine Coefficients of the components
fprintf(' 1 = Acetaldehyde\n 2 = Acetic Acid \n 3 = Acetone \n 4 = Acetylene \n 5 = Ammonia\n 6 = Argon\n 7 = Benzene \n')
for ite = 1: n
fprintf('Please enter the corresponding number for the component %i in the feed stream: \n', i);
comp(i) = input(' ');
data1 = Antoine_coefficients(comp(i),:);
a(i) = data1(1);
b(i) = data1(2);
c(i) = data1(3);
end
for i = 1:1:n
fprintf('Please input the liquid phase mole fraction of component %i: \n', i);
x(1, i) = input(' ');
end
% bubble point temp. calc
syms T [1:n]
for i = 1:1:n
% y1 = x1 * Psat/Ptotal
y(i) = x(i).*(10.^Antoine(a(i), b(i), c(i), T)./P_total); % Antoine is the user defined function which calculates Psat
end
I would really appreciate any help.
Thank in advance!
0 Comments
Accepted Answer
Star Strider
on 17 Apr 2021
Try this to create ‘T’ as a vector:
n = 5 % Define ‘n’
syms T
T = sym('T', [1 n])
producing:
T =
[T1, T2, T3, T4, T5]
Then address it as you would any other vector:
y3 = T(3)
produces:
y3 =
T3
.
2 Comments
Star Strider
on 18 Apr 2021
I have no idea howcode such as mine could have thrown that error. My code ran without error and produced the result I posted.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!