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


Groups > comp.soft-sys.math.mathematica > #9650

Re: Why the loop gain no result?

From "Nasser M. Abbasi" <nma@12000.org>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Why the loop gain no result?
Date 2012-04-15 07:16 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jmdskp$aae$1@smc.vnet.net> (permalink)
References <jmb7v4$r2e$1@smc.vnet.net>

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web