Register to reply

Need help creating a recursive script in matlab that can do this:

by darthxepher
Tags: creating, matlab, recursive, script
Share this thread:
darthxepher
#1
Jul30-10, 02:35 AM
P: 58
Need help creating a recursive script in matlab that can do this:

S = 1^2 + 2 ^2 + 3^2 + ... + n^2

: P
Thanks.
Phys.Org News Partner Science news on Phys.org
Climate change increases risk of crop slowdown in next 20 years
Researcher part of team studying ways to better predict intensity of hurricanes
New molecule puts scientists a step closer to understanding hydrogen storage
jamesrc
#2
Jul30-10, 05:54 AM
Sci Advisor
PF Gold
P: 478
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.


Register to reply

Related Discussions
Recursion in C Programming & Computer Science 12
Function is F(n) = n(n+1) General Math 4
Recursive function in a physics equation General Physics 6
Formulating an equation which utilizes a recursive function General Math 0
What is the largest number of pieces you can get by cutting a pizza Introductory Physics Homework 1