Sum of series in matlab using symsum

后端 未结 2 1203
灰色年华
灰色年华 2021-01-26 02:27

I have the following series

I tried this code but it does not print the final result...instead gives a long line of numbers!

syms n
y = symsum(1         


        
相关标签:
2条回答
  • 2021-01-26 03:12

    how about dropping the loop and use this instead:

    n=1:100
    result = sum(1./sqrt(n))
    
    >> result =
    
       18.5896
    

    I'm not sure if you want to use the symbolic sum of series function in your case since you are only dealing with a simple function.

    0 讨论(0)
  • 2021-01-26 03:14

    To answer the original question, you can convert the symbolic expression you initially got using double, to convert from a symbolic to a numeric value:

    y = double(y)
    

    Or actually:

    syms n
    y = double(symsum(1/sqrt(n),[1,100]))
    

    and you get 18.5896.

    Additionally, you can use eval to evaluate the symbolic expression (thanks Luis Mendo).

    Yay!

    0 讨论(0)
提交回复
热议问题