Jul 30, 2010 #1 darthxepher Messages 56 Reaction score 0 Need help creating a recursive script in MATLAB that can do this: S = 1^2 + 2 ^2 + 3^2 + ... + n^2 : P Thanks.
Need help creating a recursive script in MATLAB that can do this: S = 1^2 + 2 ^2 + 3^2 + ... + n^2 : P Thanks.
Jul 30, 2010 #2 jamesrc Science Advisor Gold Member Messages 471 Reaction score 1 This should do it: S = sum((1:n).^2); (1:n) creates an array of integers from 1 to n the .^2 squares each element and the sum() function does what it says.
This should do it: S = sum((1:n).^2); (1:n) creates an array of integers from 1 to n the .^2 squares each element and the sum() function does what it says.