Why does "pi" become symbolic in MATLAB? -


in matlab command window type:

syms f; s = 2*pi*f*j; s 

which returns

s =  pi*f*2*j 

why pi not calculated 3.141592...?what's wrong code entered command window?

welcome symbolic math exact answers opposed floating-point approximations. if want "get number" can use non-symbolic functions , operations or can convert symbolic results floating-point.

for example:

syms f s = pi*f*2*j s2 = subs(s,f,2) s3 = double(s2) 

alternatively, can use variable precision arithmetic represent pi decimal approximation of specified level in symbolic expression:

syms f s = vpa(pi)*f*j 

see documentation vpa further details. can use sym function achieve similar things.

however, can lose of power of symbolic math if convert decimal or floating point representation soon. example, compare difference between following expressions:

sin(pi)      % 1.224646799147353e-16 sin(vpa(pi)) % -3.2101083013100396069547145883568e-40 sin(sym(pi)) % 0, sin(sym(1)*pi) , sin(sym(pi,'r')) return 0 

only last 1 cancelled out of expression, simplifying it.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -