numerical answer required for sumation

17 views (last 30 days)
a very basic question, say i use
symsum(((-1)^(sym('k')-1))*(sin(sym('k'))), k, 0, 12)
I just get
sin(311/250) - sin(311/125) - sin(311/625) - sin(622/625) - sin(933/625) + sin(311/1250) - sin(1244/625) + sin(933/1250) - sin(1866/625) + sin(2177/1250) + sin(2799/1250) + sin(3421/1250)
but i want a single numeric value (like 0.2354 or whatever) not this expanded string of sin's. I dont want like 0.254 +0.056 +0.214 etc I just want a single value.
Ive tried searching on google but i have the normal problem of not knowing what the keyword is to search for.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Mar 2011
You can apply double() to a symbolic expression to get back the Matlab double precision number that is equivalent.
If you want the result to be a symbolic number instead, such as if you need to evaluate to more decimal places, then use vpa() on the symbolic expression.

More Answers (2)

Paulo Silva
Paulo Silva on 2 Mar 2011
double(sin(311/250)-sin(311/125)-sin(311/625)-sin(622/625)-sin(933/625)+sin(311/1250)-sin(1244/625)+sin(933/1250)-sin(1866/625)+sin(2177/1250)+sin(2799/1250)+sin(3421/1250))

Paulo Silva
Paulo Silva on 2 Mar 2011
eval('sin(311/250)-sin(311/125)-sin(311/625)-sin(622/625)-sin(933/625)+sin(311/1250)-sin(1244/625)+sin(933/1250)-sin(1866/625)+sin(2177/1250)+sin(2799/1250)+sin(3421/1250)')

Community Treasure Hunt

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

Start Hunting!