Re: How to do a simple loop?

• To: mathgroup at smc.vnet.net
• Subject: [mg30433] Re: How to do a simple loop?
• From: "Oliver Friedrich" <oliver.friedrich at tz-mikroelektronik.de>
• Date: Sat, 18 Aug 2001 04:04:57 -0400 (EDT)
• References: <9ligqt\$is2\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi Vadim,

1. To print the function i times

Table[x*i-i,{i,100}]//TableForm

It creates a list with i elements. Each element represents your desired
expression.

2. Plot the function

Scan[ Plot[ x i-i, {i,0,#}]&, Range[100]]

Range creates a table with elements 1 to 100. Scan operates the Plot
function on each of that elements. The element is inserted at the # (a so
called pure function). Careful with that x, you must replace it with a
numerical value, cause Plot won't evaluate on non-numeric expressions.

3. Find the Integral

Map[Integrate [x i-i, {x, 0, #}]&,Range[5]]

Same as above, except that Map creates a list with the result.

Have fun

Oliver Friedrich

"Vadim Nagornyi" <vnagornyi at netscape.net> schrieb im Newsbeitrag
news:9ligqt\$is2\$1 at smc.vnet.net...
> Still using 2.2 ...
> OK, I have a function that depends on an integer, for example F=x*i-i.
> For i ranging from 1 to 100 I need to perform the following:
>
> 1. Display the function equation.
> 2. Plot the function in the range 0...i
> 3. Find the integral of the function for the same range.
>
> The loop body looks simple:
>
> F
> Plot[F, {x, 0, i}]
> Integrate [F, {x, 0, i}]
>
> but how to iterare this?
>
> Thanks,