ten digits of pi in matlab

To calculate ten digits of pi in MATLAB, use the vpa function with 10 as its input argument to set the desired number of digits:

main.m
format long; % set format to display long numbers
digits(10); % set number of digits to 10
pi_val = vpa(pi); % calculate pi with 10 digits precision
disp(pi_val); % display pi value
182 chars
5 lines

The output of this code will display the value of pi with 10 digits of precision:

main.m
3.141592654
12 chars
2 lines

related categories

gistlibby LogSnag