Using "solve" on symbolic equation returns complex numbers when it shouldn't.
24 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Aquatris
2018-8-3
Because there is an imaginary root to that equation as well. If you were to evaluate your sfun using T2s you will see the result is pretty much zero, although not exactly due to numeric issues.
usubs(sfun,'T',T2s)
ans =
1.4e-33+6.4e-35i
If your symbolic variable T is real, you can define T as;
syms T real
which gave
T2s_Real = 550.71701819094995388330808691848
and after substituting the value to sfun gave
subs(sfun,'T',T2s_real)
ans =
1.45e-33
which is higher than the imaginary number solution.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Special Values 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!