Why the both results are different

I compute the little program in matlab
clear; clf;
syms a b
f1 = 96*pi - 16*pi * (log(a)-log(b)+1)
f1_ = subs(f1,[a b],[12 2])
f1_ = vpa(f1_)
f2 = 96*pi - 16*pi*(log(12)-log(2)+1)
with the output
f1 =
f1_ =
f1_ =
f2 = 161.2638
Why the results are different?

2 Comments

Ah, sorry, somehow when I formatted your code, the special characters disappeared!! If you could repost that part, that would be good.
When I test, I get
f1_ =
161.26375811875458240605931894947
f2 =
161.263758118755
The first of those has been computed to higher precision.
The first has also been computed in a mode that recognized pi as being the indefinitely precise transcendental number, whereas the second one that was calculated purely numeric was calculated with the 16-digit numeric approximation of pi.

Sign in to comment.

 Accepted Answer

With the newest Update R2020a Update 2 the problem is solved. The new output is ok
f1 =
f1_ =
f1_ =
161.26375811875458240605931894947
f2 = 161.2638

3 Comments

.. and I do happen to be using Update 2.
Which release was the problem observed with?
The answer must be modified. I found the problem is come, if I give the commend digits(2) sometimes in matlab,see:
clear; clf;
syms a b
digits(2)
f1 = 96*pi - 16*pi * (log(a)-log(b)+1)
f1_ = subs(f1,[a b],[12 2])
f1_ = vpa(f1_)
f2 = 96*pi - 16*pi*(log(12)-log(2)+1)
f3 = 96*sym(pi) - 16*sym(pi)*(log(sym(6)) + 1)
f3 = vpa(f3)
digits(32)
f1 = 96*pi - 16*pi * (log(a)-log(b)+1)
f1_ = subs(f1,[a b],[12 2])
f1_ = vpa(f1_)
f2 = 96*pi - 16*pi*(log(12)-log(2)+1)
f3 = 96*sym(pi) - 16*sym(pi)*(log(sym(6)) + 1)
f3 = vpa(f3)
gives the output
f1 =
f1_ =
f1_ =
160.0
f2 = 161.2638
f3 =
f3 =
160.0
f1 =
f1_ =
f1_ =
161.26375811875458240605931894947
f2 = 161.2638
f3 =
f3 =
161.26375811875458240605931894947
You didn't reply to sir Walter's comment though.

Sign in to comment.

More Answers (1)

why should I give an answer if digit(2) is problem?

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!