vpasolve gives different answers for the same equation
5 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to use vpasolve to solve a nonlinear equation numerically. when I insert the coefficients manually, the result seems fine but when I use variables with the same value as I put manually the result changes. It doesn't seem logical to me at all. I would appreciate any help in this regard.
Here is the code (I have put both manual and variable case so you can compare the results) :
NA = 6.022*10^23; %1/mol
R = 8.3145*10^-6; %m^3*MPa/(K*mol)
M_ps = 329; %kg/mol
T_cent = 70; %C
P = 14.8; %MPa
T = T_cent + 273.15; %K
cT_ps = 739.9; %K
cP_ps = 387; %Mpa
crho_ps = 1108; %kg/m^3
r_ps = M_ps * cP_ps / (R * cT_ps * crho_ps)
tT_ps = T / cT_ps
tP_ps = P / cP_ps
syms x
vpasolve(x^2+ tT_ps* (log(1-x) + (1-1/r_ps)*x) + tP_ps,x)
vpasolve(x^2+ 0.4638* (log(1-x) + (1-1/18679)*x)+ 0.0382,x)
0 个评论
采纳的回答
Manan Mishra
2018-1-10
编辑:Manan Mishra
2018-1-10
The difference in results is because of the values you have used in place of those variables.
The default output display format in MATLAB is "short" which gives 4 digits after the decimal point (the output gets rounded-off to 4 decimal places). To see a more precise value of those variables, you can change the output display format to "long" and then use those values in the "vpasolve" command.
>> format long
After executing this command, you can see the values with 15 digits after decimal places.
>> tT_ps
tT_ps =
0.463778889039059
>> r_ps
r_ps =
1.867918561070000e+04
>> tP_ps
tP_ps =
0.038242894056848
When you give these values to "vpasolve" command, the results are same:
>> vpasolve(x^2+ tT_ps* (log(1-x) + (1-1/r_ps)*x) + tP_ps,x)
ans =
- 0.0047320390312815607624270500579465 - 0.22208533470256431164303895468295i
>> vpasolve(x^2+ 0.463778889039059* (log(1-x) + (1-1/18679.1856107)*x)+ 0.038242894056848,x)
ans =
- 0.0047320390312815607624270500579465 - 0.22208533470256431164303895468295i
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!