# Evaluating a series

16 messages
Open this post in threaded view
|

## Evaluating a series

 Please assist me to do this: Evaluate the series 1-1/3+1/5-1/7+1/9-...+1/1001 Duncan Sent from my BlackBerry® wireless device _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave Duncan
Open this post in threaded view
|

## Re: Evaluating a series

 On Aug 9, 2012, at 9:22 AM, [hidden email] wrote: > Please assist me to do this: > Evaluate the series > > 1-1/3+1/5-1/7+1/9-...+1/1001 You can get the positive part of the sequence by doing something like   1 ./ (1:4:1001) summing that will give you part of your result. You can do the same for the negative part and subtract that from the positive part. Søren _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 Am 09.08.2012 09:30, schrieb Søren Hauberg: > On Aug 9, 2012, at 9:22 AM, [hidden email] wrote: > >> Please assist me to do this: >> Evaluate the series >> >> 1-1/3+1/5-1/7+1/9-...+1/1001 > You can get the positive part of the sequence by doing something like > >   1 ./ (1:4:1001) > > summing that will give you part of your result. You can do the same for the negative part and subtract that from the positive part. > > Søren > I have not thought very deeply about it, but wouldn't it be more stable to group every pair of differences together 1/n - 1/(n+2) = 2/( n*(n+2) ) so that only positive numbers are summed and no subtractions take place? Just a thought without details, since that sounds like homework somehow (i also matters in which order the summation is done, not really for this small example).   _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 In reply to this post by K D Kavu On Thu, Aug 9, 2012 at 3:22 AM,  <[hidden email]> wrote: > Please assist me to do this: > Evaluate the series > > 1-1/3+1/5-1/7+1/9-...+1/1001 > > Duncan > Sent from my BlackBerry® wireless device > While there may be more elegant ways to do this, you're basically trying to repeat an addition operation of items with changing value. So, you need two things: (1) an expression for the changing value. Something as a function of 'n' that gives you the right value (i.e., n=1, you get 1, n=2, you get -1/3...) (2) you need a way of adding them all together until you get up to 1/1001.  For programming or scripting languages like Octave, you can use a looping structure. maybe a for loop if you know how many elements, or a do-while loop if you want it to run until a condition is met. from within Octave, to get the syntaxyou can type: help for or help do But, it sounds like you might need something more basic to get started. I would recommend you flip through this to get a quick feel for how to use Octave: http://people.sc.fsu.edu/~sshanbhag/matlab.primer.pdf(the filename says matlab, but the document title is "GNU Octave/Matlab Primer" and it walks you through the basics. Nick J. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 On 9 August 2012 08:26, Nicholas Jankowski <[hidden email]> wrote: > On Thu, Aug 9, 2012 at 3:22 AM,  <[hidden email]> wrote: >> Please assist me to do this: >> Evaluate the series >> >> 1-1/3+1/5-1/7+1/9-...+1/1001 >> > > While there may be more elegant ways to do this, you're basically > trying to repeat an addition operation of items with changing value. e.g.     sum(1./(1:4:1001) - 1./(3:4:1001)) ? - Jordi G. H. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 On 9 August 2012 13:38, Jordi Gutiérrez Hermoso wrote: On 9 August 2012 08:26, Nicholas Jankowski <[hidden email]> wrote: > On Thu, Aug 9, 2012 at 3:22 AM,  <[hidden email]> wrote: >> Please assist me to do this: >> Evaluate the series >> >> 1-1/3+1/5-1/7+1/9-...+1/1001 >> > > While there may be more elegant ways to do this, you're basically > trying to repeat an addition operation of items with changing value. e.g.     sum(1./(1:4:1001) - 1./(3:4:1001)) ? - Jordi G. H. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave >sum(1./(1:4:1001) - 1./(3:4:1001))error: operator -: nonconformant arguments (op1 is 1x251, op2 is 1x250)error: evaluating argument list element number 1>sum(1./(1:4:1001)) - sum(1./(3:4:1001)) ans =  0.78590-- /* andy buckle */ _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 On Thu, Aug 9, 2012 at 8:46 AM, Andy Buckle <[hidden email]> wrote: > > > On 9 August 2012 13:38, Jordi Gutiérrez Hermoso <[hidden email]> wrote: >> >> On 9 August 2012 08:26, Nicholas Jankowski <[hidden email]> wrote: >> > On Thu, Aug 9, 2012 at 3:22 AM,  <[hidden email]> wrote: >> >> Please assist me to do this: >> >> Evaluate the series >> >> >> >> 1-1/3+1/5-1/7+1/9-...+1/1001 >> >> >> > >> > While there may be more elegant ways to do this, you're basically >> > trying to repeat an addition operation of items with changing value. >> >> e.g. >> >>     sum(1./(1:4:1001) - 1./(3:4:1001)) >> >> ? >> >> - Jordi G. H. >> _______________________________________________ >> Help-octave mailing list >> [hidden email] >> https://mailman.cae.wisc.edu/listinfo/help-octave> > >>sum(1./(1:4:1001) - 1./(3:4:1001)) > error: operator -: nonconformant arguments (op1 is 1x251, op2 is 1x250) > error: evaluating argument list element number 1 >>sum(1./(1:4:1001)) - sum(1./(3:4:1001)) > ans =  0.78590 > > -- > /* andy buckle */ 50 points from Gryffindor: for doing the kid's homework for him instead of leading him to actually learning to use the program. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 On 9 August 2012 14:01, Nicholas Jankowski wrote: On Thu, Aug 9, 2012 at 8:46 AM, Andy Buckle <[hidden email]> wrote: > > > On 9 August 2012 13:38, Jordi Gutiérrez Hermoso <[hidden email]> wrote: >> >> On 9 August 2012 08:26, Nicholas Jankowski <[hidden email]> wrote: >> > On Thu, Aug 9, 2012 at 3:22 AM,  <[hidden email]> wrote: >> >> Please assist me to do this: >> >> Evaluate the series >> >> >> >> 1-1/3+1/5-1/7+1/9-...+1/1001 >> >> >> > >> > While there may be more elegant ways to do this, you're basically >> > trying to repeat an addition operation of items with changing value. >> >> e.g. >> >>     sum(1./(1:4:1001) - 1./(3:4:1001)) >> >> ? >> >> - Jordi G. H. >> _______________________________________________ >> Help-octave mailing list >> [hidden email] >> https://mailman.cae.wisc.edu/listinfo/help-octave > > >>sum(1./(1:4:1001) - 1./(3:4:1001)) > error: operator -: nonconformant arguments (op1 is 1x251, op2 is 1x250) > error: evaluating argument list element number 1 >>sum(1./(1:4:1001)) - sum(1./(3:4:1001)) > ans =  0.78590 > > -- > /* andy buckle */ 50 points from Gryffindor: for doing the kid's homework for him instead of leading him to actually learning to use the program. I would not have posted the answer had Jordi not almost posted the answer...-- /* andy buckle */ _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 On Thu, Aug 9, 2012 at 9:07 AM, Andy Buckle <[hidden email]> wrote: > > > On 9 August 2012 14:01, Nicholas Jankowski <[hidden email]> wrote: >> >> On Thu, Aug 9, 2012 at 8:46 AM, Andy Buckle <[hidden email]> wrote: >> > >> > >> > On 9 August 2012 13:38, Jordi Gutiérrez Hermoso <[hidden email]> >> > wrote: >> >> >> >> On 9 August 2012 08:26, Nicholas Jankowski <[hidden email]> wrote: >> >> > On Thu, Aug 9, 2012 at 3:22 AM,  <[hidden email]> wrote: >> >> >> Please assist me to do this: >> >> >> Evaluate the series >> >> >> >> >> >> 1-1/3+1/5-1/7+1/9-...+1/1001 >> >> >> >> >> > >> >> > While there may be more elegant ways to do this, you're basically >> >> > trying to repeat an addition operation of items with changing value. >> >> >> >> e.g. >> >> >> >>     sum(1./(1:4:1001) - 1./(3:4:1001)) >> >> >> >> ? >> >> >> >> - Jordi G. H. >> >> _______________________________________________ >> >> Help-octave mailing list >> >> [hidden email] >> >> https://mailman.cae.wisc.edu/listinfo/help-octave>> > >> > >> >>sum(1./(1:4:1001) - 1./(3:4:1001)) >> > error: operator -: nonconformant arguments (op1 is 1x251, op2 is 1x250) >> > error: evaluating argument list element number 1 >> >>sum(1./(1:4:1001)) - sum(1./(3:4:1001)) >> > ans =  0.78590 >> > >> > -- >> > /* andy buckle */ >> >> 50 points from Gryffindor: for doing the kid's homework for him >> instead of leading him to actually learning to use the program. > > > I would not have posted the answer had Jordi not almost posted the answer... > > -- > /* andy buckle */ nah... it's like every other academic paper. you deliberately leave one or two typo's in the equations to force the grad students 'reimplementing' your work to re-derive the equations themselves :) _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 In reply to this post by nrjank On 9 August 2012 09:01, Nicholas Jankowski <[hidden email]> wrote: > 50 points from Gryffindor: for doing the kid's homework for him > instead of leading him to actually learning to use the program. I am not going to investigate if this alleged "kid" really is asking the internet to do this his(?) homework or not. And if he is, great, because I also ask the internet to do mine all the time ("patches welcome", etc). Anyways, you suggested using for loops, which are manifestly unnecessary for this problem. - Jordi G. H. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 On 9 August 2012 14:41, Jordi Gutiérrez Hermoso wrote: On 9 August 2012 09:01, Nicholas Jankowski <[hidden email]> wrote: > 50 points from Gryffindor: for doing the kid's homework for him > instead of leading him to actually learning to use the program. I am not going to investigate if this alleged "kid" really is asking the internet to do this his(?) homework or not. And if he is, great, because I also ask the internet to do mine all the time ("patches welcome", etc). Anyways, you suggested using for loops, which are manifestly unnecessary for this problem. - Jordi G. H. I was thinking it was the suggestion of loops that made you snap. I was wavering myself.-- /* andy buckle */ _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 On Thu, Aug 9, 2012 at 9:51 AM, Andy Buckle <[hidden email]> wrote: > > > On 9 August 2012 14:41, Jordi Gutiérrez Hermoso <[hidden email]> wrote: >> >> On 9 August 2012 09:01, Nicholas Jankowski <[hidden email]> wrote: >> > 50 points from Gryffindor: for doing the kid's homework for him >> > instead of leading him to actually learning to use the program. >> >> I am not going to investigate if this alleged "kid" really is asking >> the internet to do this his(?) homework or not. And if he is, great, >> because I also ask the internet to do mine all the time ("patches >> welcome", etc). >> >> Anyways, you suggested using for loops, which are manifestly >> unnecessary for this problem. >> >> - Jordi G. H. > > > I was thinking it was the suggestion of loops that made you snap. I was > wavering myself. > > -- > /* andy buckle */ hah... yeah, thought that would get someone up in arms. it would be bigger, uglier, slower, BUT more intelligible and educational to a programming newbie. Was basing my assumption off the level of capability hinted at by the form of the initial question. :) _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 In reply to this post by K D Kavu >Please assist me to do this: >Evaluate the series > >1-1/3+1/5-1/7+1/9-...+1/1001 Is this a home assignment? -- Francesco Potortì (ricercatore)        Voice:  +39.050.315.3058 (op.2111) ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107 via G. Moruzzi 1, I-56124 Pisa         Fax:    +39.050.315.2040 (entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it_______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: Evaluating a series

 In reply to this post by nrjank On 9 August 2012 10:45, Nicholas Jankowski <[hidden email]> wrote: > hah... yeah, thought that would get someone up in arms. it would be > bigger, uglier, slower, BUT more intelligible and educational to a > programming newbie. For this particular problem, the loopless code is more succinct and easier to understand. And nothing wrong to teach people from the beginning to avoid loopless code. That's how it was taught to me, and I think I came out alright. - Jordi G. H. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave