Increase the amount of decimals in the hyperbolic functions

3 views (last 30 days)
why matlab sinh(50) for an integer show? while it must decimal number. for what we have to n decimal places?

Accepted Answer

John D'Errico
John D'Errico on 21 Nov 2015
Edited: John D'Errico on 21 Nov 2015
You need to understand double precision. So far, I've seen two posts by you that show you are not doing so.
First, your example.
digits 100
vpa(sinh(50))
ans =
2592352764293536022528.0
Now, I'll compute the same result, using my own HPF tool.
sinh(hpf(50,100))
ans =
2592352764293536232043.726661466742692413734453854430802756139316036287616046268961598412632838901239
As you can see, HPF has no problem. What was the difference? There, I created the number 50, as an HPF number. THEN I computed sinh of that value.
What did you do, and why was it different? You started with the number 50. This is a double precision value. THEN you computed the sinh, as a double precision number, thus limited to about 16 digits of precision. And then, and only then, did you tell MATLAB to convert this to a symbolic result! What should you expect?
Just because you executed the command
digits 100
this does not tell MATLAB that ALL computations will be done in 100 digits of precision. No matter what, MATLAB does double precision computations. digits is a symbolic toolbox command, and only applies to computations done there. But even then, if you pass in a result that is only in double precision, then the symbolic toolbox cannot do magic, and undo what you have done.
So, now try this:
vpa(sinh(sym(50)))
ans =
2592352764293536232043.726661466742692413734453854430802756139316036287616046268961598412632838901239
It looks just like what HPF returned, and for good reason. The difference between the various computations above is important, as well as the reason why HPF and the symbolic TB were able to generate the correct result with no problem.
Finally, be careful with these things. Both HPF and sym had no problem with the number 50, because it is EXACTLY representable as an integer, even in double precision. So you need to understand the difference between the next two statements, and why they have a different result.
vpa(sym(50.12324545))
ans =
50.1232454499999988684066920541226863861083984375
vpa(sym('50.12324545'))
ans =
50.12324545

More Answers (0)

Community Treasure Hunt

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

Start Hunting!