numerical answer required for sumation

8 visualizaciones (últimos 30 días)
john birt
john birt el 2 de Mzo. de 2011
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de Mzo. de 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.

Más respuestas (2)

Paulo Silva
Paulo Silva el 2 de Mzo. de 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 el 2 de Mzo. de 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!

Translated by