How to get actual value instead of answer in terms of exp and pi as a output in matlab program
9 views (last 30 days)
Show older comments
mf=0.5217;
Cp1=2253.22;
Ar=1.7593;
U_L=3.1314;
F_=0.8726;
F_1 = ((mf*Cp1)/(Ar*U_L))*(1-(exp(-((U_L*F_*Ar)/(mf*Cp1)))))
When I am calculating F_1 using above lines it gives a specified value like 0.9223 but when I am using the same formula for F_1 at the end of for loop and values of mf, Cp1 are calculated in loop and Ar, U_L,F_ , are calculated at the end f the loop then F_1 gives value like
-(670.3687109128533118179408369425*(exp(-0.0013017227863710711508658689494424*pi) - 1))/pi.
What could be the reason for this and how to get rid of it...??
0 Comments
Accepted Answer
Steven Lord
on 31 Oct 2019
If you want to perform the calculations symbolically but then receive a double precision or numeric result, call double (if your expression does not contain any symbolic variables) or vpa (if it does) on the final result.
3 Comments
JUAN MANUEL PALAO
on 2 Jun 2021
Hi! Same question here but when using vpasolve function with a symbolic variable:
syms X
sigma=vpasolve(-DF+1-sin(beta1)/(mi*sin(beta2))+(ni*sin(beta1)^2)/(X*(ni+1))*((1-ni^2)/(mi*ni*psi)- cot(beta1)+cot(beta2)/(mi*ni))*(1-(M1^2*sin(beta1))/(mi*sin(beta2))*(sin(beta1)/(mi*sin(beta2)-1))),X,1);
The thing is that it does give a numerical result of "sigma", however, the variables I calculate after and depend on "sigma" are expressed in terms of pi, /, +, ^, etc.
How should I make that call "vpa" you mentioned?
Thank you in advance.
Steven Lord
on 2 Jun 2021
two = sym(2);
s = sqrt(two)
vpa(s, 6)
double(s) % Since s contains no symbolic variable this works
More Answers (1)
the cyclist
on 31 Oct 2019
I think there must be some other difference, not just being in a loop. It looks like somehow you have the Symbolic Math Toolbox involved in there. Do you see a syms command before the loop? Can you post the code that gives the two different results?
3 Comments
the cyclist
on 31 Oct 2019
If you want to do all numeric calculations, and none symbolic, then presumably you can just remove all the syms commands.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!