Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9649 > unrolled thread

Why the loop gain no result?

Started byHuafeng Cao <geotom.cao@gmail.com>
First post2012-04-14 07:11 +0000
Last post2012-04-15 07:20 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Why the loop gain no result? Huafeng Cao <geotom.cao@gmail.com> - 2012-04-14 07:11 +0000
    Re: Why the loop gain no result? "Nasser M. Abbasi" <nma@12000.org> - 2012-04-15 07:16 +0000
    Re: Why the loop gain no result? Ray Koopman <koopman@sfu.ca> - 2012-04-15 07:20 +0000

#9649 — Why the loop gain no result?

FromHuafeng Cao <geotom.cao@gmail.com>
Date2012-04-14 07:11 +0000
SubjectWhy the loop gain no result?
Message-ID<jmb7v4$r2e$1@smc.vnet.net>
Dear all,
    I use the' For' loop to solving an equation, such as :
    For[i = 1, i < 5, i++, a = i; Solve[a*x^2 - 2 x + 1 == 0, x]].The
'a' in the body must be updated in every loop with the 'i'. But i
cann' t gain the result,Somewhere is disorder? I am confused.
  Thinks in advanced!





Geotom.Cao
GUCAS

[toc] | [next] | [standalone]


#9650

From"Nasser M. Abbasi" <nma@12000.org>
Date2012-04-15 07:16 +0000
Message-ID<jmdskp$aae$1@smc.vnet.net>
In reply to#9649
On 4/14/2012 2:11 AM, Huafeng Cao wrote:
> Dear all,
>      I use the' For' loop to solving an equation, such as :
>      For[i = 1, i<  5, i++, a = i; Solve[a*x^2 - 2 x + 1 == 0, x]].The
> 'a' in the body must be updated in every loop with the 'i'. But i
> cann' t gain the result,Somewhere is disorder? I am confused.
>    Thinks in advanced!
>
>

You can use Reap/Sow to collect the result:

Rest@Reap[For[i = 1, i < 5, i++,
    a = i;
    Sow[Solve[a*x^2 - 2 x + 1 == 0, x]]
    ]]

ps. If you want to see each step, you need to use Print[] inside For:

For[i = 1, i < 5, i++,
  a = i;
  Print@Solve[a*x^2 - 2 x + 1 == 0, x]
  ]


--Nasser

[toc] | [prev] | [next] | [standalone]


#9658

FromRay Koopman <koopman@sfu.ca>
Date2012-04-15 07:20 +0000
Message-ID<jmdssj$adc$1@smc.vnet.net>
In reply to#9649
On Apr 14, 12:11 am, Huafeng Cao <geotom....@gmail.com> wrote:
> I use the 'For' loop to solving an equation, such as :
>     For[i = 1, i < 5, i++, a = i; Solve[a*x^2 - 2 x + 1 == 0, x]].
> The 'a' in the body must be updated in every loop with the 'i'.
> But i can't gain the result, Somewhere is disorder? I am confused.

No, you don't need the 'a'. But if you want to see the results
then you need to Print them:
  For[i = 1, i < 5, i++, Print@Solve[i*x^2 - 2 x + 1 == 0, x]]
or put them in a Table:
  Table[Solve[i*x^2 - 2 x + 1 == 0, x], {i,4}]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web