FSOLVE requires all values returned by functions to be of data type double
40 views (last 30 days)
Show older comments
clc;
clear;
clear all;
close all;
% defining inputs
N = 2;
Mf = 100;
Xf = 0.045;
Xn = 0.1;
Tf = 30;
To = 110;
deltaT = 40;
Cf=4.18;
Do=30.0;
% entering U values
for I=1:N
prompt='enter u values';
x= input (prompt) ;
u(I)= x;
end
% entering Cp values
for i=1:N
prompt='enter cp values';
x=input(prompt);
cp(i)=x;
end
% overall material balance
Bn=Mf*Xf/Xn ;
D=Mf-Bn;
disp(Bn)
disp(D)
% sum of i/ui
usum=0;
for i=1:N
usum=usum+(1/u(i))
end
disp(usum)
% calculating deltT for each effect
delT(1)=deltaT/(u(1)*usum);
disp(delT(1));
for i=2:N
delT(i)=u(1)*delT(1)/u(i);
end
% calculating temperature for each effect
for i=1:N
x=0;
for j=1:i
x = x+delT(j)
end
T(i)=To-x;
end
% latent heat of vaporization
for i=1:N
lamda(i)=2589.583+.9156*T(i)-4.8343*10^-2 *T(i)^2 ;
end
lamdao=2589.583+.9156*To-4.8343*10^-2 *To^2 ;
disp(lamda)
% Enthalpy Balance
for i=1:N
Bo(i)=0;
end
[B,fval] = fsolve(@(B)@ourfun,Bo);
%disp (B);
function F = ourfun(B)
F(1)=Do*lamdao + B(1)*lamda(1)+Mf*(Cf*(Tf-T(1))+lamda(1));
F(2)=B(1)*(cp(1)*(T(1)-T(2))-lamda(1)-lamda(2))+B(2)*lamda(2)+Mf*lamda(1);
for i=3:N
F(i)=B(i-1)*(Cp(i-1)*(T(i-1)-T(i))-lamda(i-1)-lamda(i))+B(i)*lamda(i)+B(i-2)*lamda(i-1);
end
end
Result:
Error using fsolve (line 287)
FSOLVE requires all values returned by functions to be of data type double.
Error in MEE (line 63)
[B,fval] = fsolve(@(B)@ourfun,Bo);
0 Comments
Accepted Answer
Stephen23
on 22 Jan 2020
Edited: Stephen23
on 22 Jan 2020
The function handle definition is incorrect:
@(B)@ourfun
What you defined is an anonymous function which when called accepts one input argument named B (which is totally ignored) and returns a function handle to a function named ourfun. This is not very useful for fsolve.
Read about function handles:
Note that you will also need to parameterize your function, otherwise your code will not work:
Using a nested function would be easiest, as then you could simply call your (nested) function like this:
[B,fval] = fsolve(@ourfun,Bo);
More Answers (0)
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!