# How to stop pi appearing as a text in the disp result?

2 views (last 30 days)
Tuna Dikmen on 23 Apr 2023
Commented: Image Analyst on 23 Apr 2023
I want to estimate the value of cos(pi/4) using the taylor series expansion around the point x=0, here is my code,
syms x
f= cos(x);
t6= taylor(f,x);
val=subs(t6,x,pi/4);
disp(val);
I expect the result as a floating number however the result is printed as : pi^4/6144 - pi^2/32 + 1
How can I overcome this?

Dyuman Joshi on 23 Apr 2023
Convert the symbolic value to floating point value -
format long
syms x
f = cos(x);
t6 = taylor(f,x);
val = double(subs(t6,x,pi/4));
disp(val)
0.707429206709773
Image Analyst on 23 Apr 2023
Sorry, you're right.

Image Analyst on 23 Apr 2023
I suggest you don't use symbolic terms at all. I suggest you just do it numerically with a for loop to sum some number of terms (like a thousand or so).

Walter Roberson on 23 Apr 2023
sympref('FloatingPointOutput', true);
syms x
f= cos(x);
t6= taylor(f,x);
val=subs(t6,x,pi/4);
disp(val);
0.7074
I do not recommend this approach: there is not much control over the number of digits output, and there are (in my opinion) too many places where you would want symbolic instead of floating point values.