Using "solve" on symbolic equation returns complex numbers when it shouldn't.
Show older comments
I have created a symbolic equation "sfun". When I try to use the "solve" function on sfun I get a complex (imaginary) number. However, when I run "fplot" on the same function you can clearly see that y = 0 around when x = 550. Why am I getting complex numbers? Thanks, Matt
global Cp T R;
%constants
rbar = 8.314;
M = 28.97;
A = 3.653;
B = -1.337*10^-3;
C = 3.294*10^-6;
D = -1.913*10^-9;
E = 0.2763*10^-12;
Ph = 990;
Pl = 100;
T1 = 288.15;
%derived constants
R = rbar/M;
Rp = Ph/Pl;
%variables
syms T;
%equations
Cp = R*(A + B*T + C*T^2 + D*T^3 + E*T^4);
%main
h1 = deltah(0, T1);
h1 = double(h1);
sfun = deltas(288.15, T, 100, 990);
T2s = solve(sfun == 0, T)
fplot(sfun, [400, 600])
%functions
function h = deltah(T1, T2)
global Cp T;
h = int(Cp, T, [T1 T2]);
end
function s = deltas(T1, T2, P1, P2)
global Cp T R;
s = int(Cp/T, T, [T1 T2]) - R*reallog(P2/P1);
end

Accepted Answer
More Answers (0)
Categories
Find more on Symbolic Math Toolbox 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!