Help

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Help

joseph appau
How do I use octave to evaluate the following,  1^2 + 2^2 +3^2 +...+100^2


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Help

Jordi Gutiérrez Hermoso-2
On 18 February 2012 10:40, Appau Joseph <[hidden email]> wrote:
> How do I use octave to evaluate the following,  1^2 + 2^2 +3^2 +...+100^2

sumsq(1:100)

HTH,
- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Help

Doug Stewart-4
In reply to this post by joseph appau


On Sat, Feb 18, 2012 at 10:40 AM, Appau Joseph <[hidden email]> wrote:
How do I use octave to evaluate the following,  1^2 + 2^2 +3^2 +...+100^2


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave


there are many ways: this is one way

a=1:100;
b=a.^2;
c=sum(b)

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Help

James Sherman
In reply to this post by joseph appau


On Sat, Feb 18, 2012 at 10:40 AM, Appau Joseph <[hidden email]> wrote:
How do I use octave to evaluate the following,  1^2 + 2^2 +3^2 +...+100^2



s = 0;
for i = 1:100,
  s = s + i^2;
endfor

or you could vectorize the loop and get:

s = sum((1:100).^2);




_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Help

pathematica
Another variation offered to give further insight into what octave does (rather than indulging in gratuitous competitive spirit). Honest.

(1:100)*(1:100)'

OK. Maybe it would be more honest to say "as well as"
However good you think Octave is, it's much, much better.
Reply | Threaded
Open this post in threaded view
|

Re: Help

Liam Groener-2
Sent from my iPad

On Feb 18, 2012, at 10:17 AM, pathematica <[hidden email]> wrote:

> Another variation offered to give further insight into what octave does
> (rather than indulging in gratuitous competitive spirit). Honest.
>
> (1:100)*(1:100)'
>
> OK. Maybe it would be more honest to say "as well as"
>
> -----
> However good you think Octave is, it's much, much better.
If we are showing off, how about

100*101*201/6

(sum(n^2)) = n*(n+1)*(2*n+1)/6)
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Help

pathematica
This post was updated on .
Liam Groener-2 wrote
If we are showing off, how about

(sum(n^2)) = n*(n+1)*(2*n+1)/6)
Not bad!

How about

norm(1:100)^2

However good you think Octave is, it's much, much better.
Reply | Threaded
Open this post in threaded view
|

Re: Help

pathematica
This will also work

100*var(-100:100)
However good you think Octave is, it's much, much better.