Conversion to double from function_handle is not possible.

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 part of the code is where the error occurs. The error is: Conversion to double from function_handle is not possible, and occurs in the line y(1,i) =@(T) x(1,i).*(10.^(logP(T)./P_total)); .
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
T = sym('T', [1 n]);
ytotal = zeros(1, n);
for i = 1:n
logP = @(T) a(i) - (b(i)./(T+c(i)));
y(1,i) =@(T) x(1,i).*(10.^(logP(T)./P_total));
ytotal = ytotal + y(i);
y(i) = y(i+1);
end

 Respuesta aceptada

Non-scalar arrays of function handles are not allowed. Either make the function handle and use it without storing it for long-term use or make a cell array of function handles.
y = zeros(1, 10);
g = cell(1, 10);
for k = 1:10
f = @(x) x.^k;
y = y + f(1:10);
g{k} = @(x) k*x;
end
format longg
y
y = 1×10
10 2046 88572 1398100 12207030 72559410 329554456 1227133512 3922632450 11111111110
g{5}(6) % 30
ans =
30

Más respuestas (0)

Preguntada:

el 22 de Abr. de 2021

Comentada:

el 23 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by