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


by darthxepher
Tags: creating, matlab, recursive, script
darthxepher
darthxepher is offline
#1
Jul30-10, 02:35 AM
P: 59
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
Review: With Galaxy S5, Samsung proves less can be more
Making graphene in your kitchen
Study casts doubt on climate benefit of biofuels from corn residue
jamesrc
jamesrc is offline
#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