I´m trying to show 16 decimal place of a result. The code I put is this
clear x;
x = 0.245;
1-x+1/2*x.^2-1/6*x.^3+1/24*x.^4
sprint('%0.16f', ans)
Matlab give me this answer
ans =
0.7827
??? Undefined function or method 'sprint' for input arguments of type 'char'.
I have two question:
- What happen? I think I used it before and I had no problems with 'sprintf' for show a result with several decimal places.
- What can I do to show more decimal places?
Thank you!
Well, I think 'vpa' this help me to show more decimal places
EDIT: and this is the matlab answer:
I think you did not use
sprint
before. There is no MATLAB intrinsic function calledsprint
, you ought to usesprintf
.sprintf
formats data into a string; it does not display it for output. Furthermore, it'ssprintf
, notsprint
, which is the function you've typed- and that MATLAB is complaining about. (It doesn't know whatsprint
is, but it knows aboutsprintf
.)If you mean to save ans to a string as a number to 16 decimal places, use
sprintf
. To just display it, which I think is what you want, useprintf
instead. In either case, the issue is clear; you forgot thef
insprintf
!