If f is deined according to
f[x_] := Piecewise[{{1, x < 1}, {2, x > 1}}]
then
Max[f[Range[0, 1, .001]]]
does not yield the desired result. What's the proper way to approach
this?
Thanks!
Aaron
Either give f the Listable Attribute, or Map f onto the list generated by
Range. As defined by you f does not work with a List as an argument
--
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/
"Aaron Fude" <aaro...@gmail.com> wrote in message
news:g4vk81$9pv$1...@smc.vnet.net...
Compare:
f[Range[0,2,.1]]
Map[f[#] &, Range[0, 2, .1]]
Map[f, Range[0, 2, .1]]
f /@ Range[0, 2, .1]
WCC
On Tue, Jul 8, 2008 at 7:48 AM, Aaron Fude <aaro...@gmail.com> wrote:
> f[x_] := Piecewise[{{1, x < 1}, {2, x > 1}}]
>
> then
>
> Max[f[Range[0, 1, .001]]]
>
> does not yield the desired result. What's the proper way to approach
> this?
>
--
W. Craig Carter
f is not Listable. One way to achieve the behaviour you expect is to
set this attribute on it:
SetAttributes[f, Listable]
But it may be simpler and better to just use Max[f /@ Range[0,1,.001]]
does not yield the desired result."
You haven't told us what the desired result IS, but I'm sure you're right.
Here's one possibility:
f[x_] = Piecewise[{{1, x < 1}, {2, x > 1}}];
Max[f /@ Range[0, 1, .001]]
1
Note that we have
f[1]
0
since 1 is neither < 1 nor > 1.
Bobby
On Tue, 08 Jul 2008 06:48:46 -0500, Aaron Fude <aaro...@gmail.com> wrote:
> Hi,
>
> If f is deined according to
>
> f[x_] := Piecewise[{{1, x < 1}, {2, x > 1}}]
>
> then
>
> Max[f[Range[0, 1, .001]]]
>
> does not yield the desired result. What's the proper way to approach
> this?
>
> Thanks!
>
> Aaron
>
>
f[x_] := Piecewise[{{1, x < 1}, {2, x > 1}}]
Max[f[Range[0, 1, .001]]]
1
Bob Hanlon
---- Aaron Fude <aaro...@gmail.com> wrote:
=============
>If f is deined according to
>f[x_] := Piecewise[{{1, x < 1}, {2, x > 1}}]
>then
>Max[f[Range[0, 1, .001]]]
>does not yield the desired result. What's the proper way to approach
>this?
To find maxima of functions use Maximize or NMaximize
For example,
Maximize[{f[x], 0 < x < 1}, x]
gives:
{1,{x->1/2}}
The first value is the function maximum and the second is the
value of x where that maximum occurs. In your particular
example, the point at which the maximum occurs is not well
defined since you have defined the function to have a constant
value for 0 < x < 1
f[x_?NumericQ] := Piecewise[{{1, x < 1}, {2, x > 1}}]
f[x_List] := f /@ x
or the attribute Listable for f[] may help.
Regards
Jens
SetAttributes[f, Listable]
Max[f[Range[0, 1, .001]]]
1
Regards,
-- Jean-Marc
--- On Wed, 7/9/08, Jean-Marc Gulliet <jeanmarc...@gmail.com> wrote:
> What are the best references you know for programming genetic algorithms in
> Mathematica?
Excellent resources I am aware of, at the introductory level, are:
[1] Christian Jacob, *Illustrating Evolutionary Computation with
Mathematica*, _The Morgan Kaufmann Series in Artificial Intelligence_,
hardcover 578 pages, Morgan Kaufmann; 1st edition (February 1, 2001)
ISBN-13: 978-1558606371
[2] The companion website for Christian Jacob's book, *Illustrating
Evolutionary Computation with Mathematica*, website that contains
numerous Mathematica notebooks.
http://pages.cpsc.ucalgary.ca/~jacob/IEC/IEC%20Main%20Page/IEC%20Main%20Page.htm
[3] Claudio Mattiussi, *Bio-inspired Adaptive Machines: Genetic
algorithms for function optimization*, Laboratory Material,
"In this laboratory you will experiment with various illustrative and
real-world applications of Genetic Algorithms (GA). The first three
examples are implemented as Mathematica notebooks.You will find a
detailed description of these exercises in the pdf files linked below.
Some basics on the Mathematica interface are given in the pdf file
describing the first exercise." (From Claudio Mattiussi's website.)
http://lissrv1.epfl.ch/~claudio/education/BAM/GAs.php
Regards,
--
Jean-Marc