- .
Funny. While it was considered obsolete and superseded by FoldList in
Mathematica 2, Mathematica 1 (!) already did
have a function Accumulate, defined as
Accumulate[f, g[e1, e2, e3, ...]] <==> g[e1, f[e1, e2], f[f[e1, e2], e3],
...]
so that
Accumulate[Plus, Range[5]] <==> {1, 3, 6, 10, 15}
However, Accumulate in Mathematica 1 clearly was not restricted to
Plus
but rather specifically intended for dealing
with functions that take exactly two arguments - so, I believe that
Accumulate in Mathematica 6 is much less usable
than the former in Mathematica 1.
Maybe I'm missing something here - but what was the rationale behind
re-implementing Accumulate in such a restricted
version now?
/oskar
===
Subject: Ordering function weird?
say I've got two sets of number, x and y, which I want to rank. See the
example below. I totally expect and want the result of Ordering[x]. But
I neiter understand nor expect the result of Ordering[y]. Both Sort[x]
and Sort[y] are ok.
Can anybody explain to me Ordering[y]?
Claus
In[3]:= x = {1, 2, 3, 6, 10, 3, 4}
y = {1, 2, 7, 8, 9, 1, 2}
Out[3]= {1, 2, 3, 6, 10, 3, 4}
Out[4]= {1, 2, 7, 8, 9, 1, 2}
In[5]:= Sort[x]
Sort[y]
Out[5]= {1, 2, 3, 3, 4, 6, 10}
Out[6]= {1, 1, 2, 2, 7, 8, 9}
In[7]:= Ordering[x]
Ordering[y]
Out[7]= {1, 2, 3, 6, 7, 4, 5}
Out[8]= {1, 6, 2, 7, 3, 4, 5}
===
Subject: Re: Ordering function weird?
(y[[#]] & /@ Ordering[y]) - Sort[y]
may help you.
Otherwise read the Help text for Ordering is say
Ordering[list] gives the positions in list at which each successive
element of Sort[list] appears.
Jens
> say I've got two sets of number, x and y, which I want to rank. See the
> example below. I totally expect and want the result of Ordering[x]. But
> I neiter understand nor expect the result of Ordering[y]. Both Sort[x]
> and Sort[y] are ok.
> Can anybody explain to me Ordering[y]?
> Claus
> In[3]:= x = {1, 2, 3, 6, 10, 3, 4}
> y = {1, 2, 7, 8, 9, 1, 2}
Out[3]= {1, 2, 3, 6, 10, 3, 4}
Out[4]= {1, 2, 7, 8, 9, 1, 2}
In[5]:= Sort[x]
> Sort[y]
Out[5]= {1, 2, 3, 3, 4, 6, 10}
Out[6]= {1, 1, 2, 2, 7, 8, 9}
In[7]:= Ordering[x]
> Ordering[y]
Out[7]= {1, 2, 3, 6, 7, 4, 5}
Out[8]= {1, 6, 2, 7, 3, 4, 5}
>
===
Subject: Re: Ordering function weird?
> say I've got two sets of number, x and y, which I want to rank. See the
> example below. I totally expect and want the result of Ordering[x]. But
> I neiter understand nor expect the result of Ordering[y]. Both Sort[x]
> and Sort[{1, 2, 7, 8, 9, 1, 2}] are ok.
which each successive element of Sort[list] appears. (Emphasize added.)
In other words, *Ordering* returns a list of _indices_ rather than a
list of sorted elements. For instance, Ordering[{1, 2, 7, 8, 9, 1, 2}]
returns the list of indices {1, 6, 2, 7, 3, 4, 5} that must be read as,
If one wants the list of integers {1, 2, 7, 8, 9, 1, 2} in ascending
order (the default), one must take the first integer of the original
list (i.e. one), then the sixth integer (i.e. one again but at a
different position), then the second (i.e. two), then the seventh (i.e.
two again but also at a different position), then the third (i.e.
seven), then the fourth (i.e. eight, and finally the fifth (i.e. nine)
resulting in the new sorted in ascending order list {1, 1, 2, 2, 7, 8,
9}, list which is identical to what is returned by Sort[{1, 2, 7, 8, 9,
1, 2}].
In[1]:= x = {1, 2, 3, 6, 10, 3, 4};
y = {1, 2, 7, 8, 9, 1, 2};
Sort[x]
Sort[y]
Out[3]= {1, 2, 3, 3, 4, 6, 10}
Out[4]= {1, 1, 2, 2, 7, 8, 9}
In[5]:= Ordering[x]
Ordering[y]
Out[5]= {1, 2, 3, 6, 7, 4, 5}
Out[6]= {1, 6, 2, 7, 3, 4, 5}
In[7]:= x[[%%]]
y[[%%]]
Out[7]= {1, 2, 3, 3, 4, 6, 10}
Out[8]= {1, 1, 2, 2, 7, 8, 9}
Out[9]= {True, True}
--
Jean-Marc
===
Subject: Re: Ordering function weird?
Claus,
Read the Help for Ordering carefully.
y = {1, 2, 7, 8, 9, 1, 2}
Sort[y]
Ordering[y]
The identity between Ordering and Sort is as follows:
Part[y, Ordering[y]] == Sort[y]
This spells it out in more detail:
Column@MapThread[
Row[{Element number , #1, [Equal] , #2,
in Sort[y] is in position , #3, [Equal] , Part[y, #3],
in y}] &, {Range[Length[y]], Sort[y], Ordering[y]}]
The advantage of Ordering is that you could now reorder another equal length
list, say the x list, in the same way that Sort[y] reordered the y list.
--
David Park
djmpark@comcast.net
http://home.comcast.net/~djmpark/
> say I've got two sets of number, x and y, which I want to rank. See the
> example below. I totally expect and want the result of Ordering[x]. But
> I neiter understand nor expect the result of Ordering[y]. Both Sort[x]
> and Sort[y] are ok.
> Can anybody explain to me Ordering[y]?
> Claus
In[3]:= x = {1, 2, 3, 6, 10, 3, 4}
> y = {1, 2, 7, 8, 9, 1, 2}
> Out[3]= {1, 2, 3, 6, 10, 3, 4}
> Out[4]= {1, 2, 7, 8, 9, 1, 2}
> In[5]:= Sort[x]
> Sort[y]
> Out[5]= {1, 2, 3, 3, 4, 6, 10}
> Out[6]= {1, 1, 2, 2, 7, 8, 9}
> In[7]:= Ordering[x]
> Ordering[y]
> Out[7]= {1, 2, 3, 6, 7, 4, 5}
> Out[8]= {1, 6, 2, 7, 3, 4, 5}
>
===
Subject: Re: Ordering function weird?
*This message was transferred with a trial version of CommuniGate(tm) Pro*
> say I've got two sets of number, x and y, which I want to rank. See
> the
> example below. I totally expect and want the result of Ordering[x].
> But
> I neiter understand nor expect the result of Ordering[y]. Both Sort[x]
> and Sort[y] are ok.
> Can anybody explain to me Ordering[y]?
> Claus
In[3]:= x = {1, 2, 3, 6, 10, 3, 4}
> y = {1, 2, 7, 8, 9, 1, 2}
> Out[3]= {1, 2, 3, 6, 10, 3, 4}
> Out[4]= {1, 2, 7, 8, 9, 1, 2}
> In[5]:= Sort[x]
> Sort[y]
> Out[5]= {1, 2, 3, 3, 4, 6, 10}
> Out[6]= {1, 1, 2, 2, 7, 8, 9}
> In[7]:= Ordering[x]
> Ordering[y]
> Out[7]= {1, 2, 3, 6, 7, 4, 5}
> Out[8]= {1, 6, 2, 7, 3, 4, 5}
>
Well, just look at the Help message for Ordering:
Ordering gives the positions in list at which each successive
element of Sort[list]
appears.
So now, your list is y = {1, 2, 7, 8, 9, 1, 2}. Your Sort[list] is
Sort[y]
{1, 1, 2, 2, 7, 8, 9}
So the first element of Sort[y] is 1 and it appears in positions 1
and 6 in your original list. The next successive element is 2 (the
second 1 is not counted) and it appears in positions 2 and 7, etc. So
Ordering[y[ should be
{1,6,2,7 ...} and indeed it is
Ordering[y]
{1, 6, 2, 7, 3, 4, 5}
Andrzej Kolowski
===
Subject: Re: Ordering function weird?
> say I've got two sets of number, x and y, which I want to rank. See the
> example below. I totally expect and want the result of Ordering[x]. But
> I neiter understand nor expect the result of Ordering[y]. Both Sort[x]
> and Sort[y] are ok.
> Can anybody explain to me Ordering[y]?
What do you find weird about it? It gives the result I expect:
y[[Ordering[y]]] is the same as Sort[y].
> In[3]:= x = {1, 2, 3, 6, 10, 3, 4}
> y = {1, 2, 7, 8, 9, 1, 2}
Out[3]= {1, 2, 3, 6, 10, 3, 4}
Out[4]= {1, 2, 7, 8, 9, 1, 2}
In[5]:= Sort[x]
> Sort[y]
Out[5]= {1, 2, 3, 3, 4, 6, 10}
Out[6]= {1, 1, 2, 2, 7, 8, 9}
In[7]:= Ordering[x]
> Ordering[y]
Out[7]= {1, 2, 3, 6, 7, 4, 5}
Out[8]= {1, 6, 2, 7, 3, 4, 5}
>
--
Szabolcs
===
Subject: Re: Ordering function weird?
Claus schrieb am 27.10.2007 12:01:
> Can anybody explain to me Ordering[y]?
> In[3]:= x = {1, 2, 3, 6, 10, 3, 4}
> y = {1, 2, 7, 8, 9, 1, 2}
> In[7]:= Ordering[x]
> Ordering[y]
Out[7]= {1, 2, 3, 6, 7, 4, 5}
Out[8]= {1, 6, 2, 7, 3, 4, 5}
>
y[[Ordering[y]]] is a sorted list. Seems ok. What's weird on it?
In[9]:= y[[Ordering[y]]]
Out[9]= {1,1,2,2,7,8,9}
===
Subject: Re: Ordering function weird?
Ordering works exactly the same way on both x and y; I have no idea what
you think is different.
y = {1, 2, 7, 8, 9, 1, 2}
Ordering@y
y[[Ordering@y]]
Sort@y
{1, 2, 7, 8, 9, 1, 2}
{1, 6, 2, 7, 3, 4, 5}
{1, 1, 2, 2, 7, 8, 9}
{1, 1, 2, 2, 7, 8, 9}
Ordering@y gives the positions, in y, of the elements of Sort@y. The first
element of Sort@y (1) is the first element of y, the second element of
Sort@y (also 1) is the 6th element of y, the third element of Sort@y (2)
is the 2nd element of y, the fourth element of Sort@y (2 again) is the 7th
element of y, and so on.
Bobby
> say I've got two sets of number, x and y, which I want to rank. See the
> example below. I totally expect and want the result of Ordering[x]. But
> I neiter understand nor expect the result of Ordering[y]. Both Sort[x]
> and Sort[y] are ok.
> Can anybody explain to me Ordering[y]?
> Claus
In[3]:= x = {1, 2, 3, 6, 10, 3, 4}
> y = {1, 2, 7, 8, 9, 1, 2}
> Out[3]= {1, 2, 3, 6, 10, 3, 4}
> Out[4]= {1, 2, 7, 8, 9, 1, 2}
> In[5]:= Sort[x]
> Sort[y]
> Out[5]= {1, 2, 3, 3, 4, 6, 10}
> Out[6]= {1, 1, 2, 2, 7, 8, 9}
> In[7]:= Ordering[x]
> Ordering[y]
> Out[7]= {1, 2, 3, 6, 7, 4, 5}
> Out[8]= {1, 6, 2, 7, 3, 4, 5}
>
--
DrMajorBob@bigfoot.com
===
Subject: Re: Ordering function weird?
> say I've got two sets of number, x and y, which I want to rank. See the
> example below. I totally expect and want the result of Ordering[x]. But
> I neiter understand nor expect the result of Ordering[y]. Both Sort[x]
> and Sort[y] are ok.
> Can anybody explain to me Ordering[y]?
> Claus
> In[3]:= x = {1, 2, 3, 6, 10, 3, 4}
> y = {1, 2, 7, 8, 9, 1, 2}
Out[3]= {1, 2, 3, 6, 10, 3, 4}
Out[4]= {1, 2, 7, 8, 9, 1, 2}
In[5]:= Sort[x]
> Sort[y]
Out[5]= {1, 2, 3, 3, 4, 6, 10}
Out[6]= {1, 1, 2, 2, 7, 8, 9}
In[7]:= Ordering[x]
> Ordering[y]
Out[7]= {1, 2, 3, 6, 7, 4, 5}
Out[8]= {1, 6, 2, 7, 3, 4, 5}
>
Ordering[x] is a permutation - the one which turns x into Sort[x].
Thus, if Sort[x][[i]] came from position j in x, then Ordering[x][[i] =
j.
In your example, y = {1, 2, 7, 8, 9, 1, 2},
Sort[y] = {1, 1, 2, 2, 7, 8, 9}.
Element 1 of Sort[y] came from position 1 in y. Therefore element 1 of
Ordering[y] is 1.
Element 2 of Sort[y] came from position 6 in y. Therefore element 2 of
Ordering[y] is 6.
Iit appears that equal elements in the original list retain their
original order.
Element 3 of Sort[y] came from position 2 in y. Therefore element 3 of
Ordering[y] is 2.
Element 4 of Sort[y] came from position 7 in y. Therefore element 4 of
Ordering[y] is 7.
And so on.
The text in the online documentation is the position in /list/ at
which each successif element of 'Sort'[/list/] appears. If you
expected to see the position in 'Sort'[/list/] of each successive
element in /list/, then you would have expected the inverse
permutation to the one that Ordering gave you.
A permutation and its inverse are usually different. I notice that in
your example x, where Ordering[x] = {1, 2, 3, 6, 7, 4, 5}, this
permutation is its own inverse. (The odds against this were 47:1.)
--
Chris Henrich
http://www.mathinteract.com
God just doesn't fit inside a single religion.
===
Subject: Integers in Reduce function
>
>> The correct answer is (b).
Actually, the answer is (a): Element[x|y,domain] means that both x and y
are elements of the specified domain.
In[1]:= Reduce[Element[x|y, Integers]]
Out[1]= x [Element] Integers && y [Element] Integers
In[2]:= Element[Sqrt[2]|E, Algebraics]
Out[2]= False
In[3]:= Element[#, Algebraics]& /@ {Sqrt[2], E}
Out[3]= {True, False}
Bhuvanesh,
> Wolfram Research
>
--
Jean-Marc
===
Subject: Usage button in Information (?) request
Hi all,
I decided to roll all of my most frequently used functions into
a package. I created documentation notebooks, which I can
read in the Documentation Center and I set my function::usage
so that I can get information from ?function. But I can't figure
out how to get the little >> to appear so I can click the link
to view the documentation notebook.
to live in the function::usage, but is somehow auto-generated
by Information itself. When I tried to add an explicit hyperlink
to usage, it broke. Does anybody know how to get the link
to appear?
Saul Cohen
===
Subject: Default font does not look good
I just upgraded from Mathematica 5.0 to 6.0 on a Mac running MacOS 10.4. I
find the default font in notebooks is not as crisp as it used to be --
less readable. Are fonts rendered differently in 6.0? How do I get
the Mathematica 5.0 look back?
Tony
===
Subject: Re: Default font does not look good
> I just upgraded from Mathematica 5.0 to 6.0 on a Mac running MacOS 10.4.
I
> find the default font in notebooks is not as crisp as it used to be --
> less readable. Are fonts rendered differently in 6.0?
Yes, they are.
> How do I get the Mathematica 5.0 look back?
The default font for versions 4.1-5.2 on Mac OS X (and previous
versions on Mac OS 7-9) was a special bitmap version of Courier which
was included with Mathematica. This ancient font is not compatible
with the modern font rendering engine used by Mathematica 6. So, in
short, there is no way to get the exact same look as Mathematica 5.0
using Mathematica 6.0.
-Rob
===
Subject: Re: Graphics export to BMP and JPEG
Hi Hannes,
Regaring the part of your question about saving images, you could
simply do the folowing:
1. Select the image you have
2. Go to the file menu
3. Select the option: save selection as
4. Choose the type of format you want
I hope that would be helpful
===
Subject: Re: Graphics export to BMP and JPEG
regarding the WHY question of Jens-Peer - unfortunately my company
forces me to use certain file types, although, I agree, vector
graphics as postscript would provide better quality.
By the way, already the Export to WMF which supports vector graphics
leads to a distorted image.
Jens statement you will never have the right size/resolution. is not
correct: If I select the image and save it via the file menu in a
bitmap format, the result is completely okay. So it should be possible
to achieve the same result with Export.
need something which can be used in a package to automate the
conversion task.
Currently I call ghostscript from the package for this purpose. But
obviously a self-contained solution within Mathematica would be better
in situations, when ghostscript is not available. So it would be good
to know how to reproduce for the call to Export the conversion options
used by Mathematica in the File -> Save selection as menu.
Below I include an example graphics which I had trouble to convert.
Hannes
!(*
GraphicsBox[
GraphicsComplexBox[{{-3., 0.}, {1.4, 0.}, {3.7, 14.5}, {4.5,
14.4}, {10.1, 24.2}}, {{{}, {},
{GrayLevel[0], Thickness[Medium], LineBox[{1, 2, 3, 4, 5}]}}, {
{GrayLevel[0], Thickness[Medium],
TagBox[InsetBox[[EmptyCircle], 1],
InsetString],
TagBox[InsetBox[[EmptyCircle], 2],
InsetString],
TagBox[InsetBox[[EmptyCircle], 3],
InsetString],
TagBox[InsetBox[[EmptyCircle], 4],
InsetString],
TagBox[InsetBox[[EmptyCircle], 5],
InsetString]}, {}}}],
AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948],
Axes->True,
AxesOrigin->{0, 0},
BaseStyle->{FontFamily -> Arial, FontSize -> Medium},
Epilog->{{
TagBox[
InsetBox[1, {-3, 0}, {0, -1.5}], InsetString],
TagBox[
InsetBox[2, {1.4, 0.}, {0, -1.5}], InsetString],
TagBox[
InsetBox[3, {3.7, 14.5}, {0, -1.5}], InsetString],
TagBox[
InsetBox[4, {4.5, 14.4}, {0, -1.5}], InsetString],
TagBox[
InsetBox[5, {10.1, 24.2}, {0, -1.5}], InsetString]},
GrayLevel[1],
RectangleBox[{-2.1, -1}, {-1.9, 1}],
GrayLevel[0],
LineBox[{{-2.1, -1}, {-2.1, 1}}],
LineBox[{{-1.9, -1}, {-1.9, 1}}],
Thickness[Medium],
Dashing[{Medium}],
LineBox[{{1.4, 0}, {4.2, 14.4}}],
Dashing[{}],
ArrowBox[{{4.2, 9.4}, {4.2, 14.4}}],
TagBox[
InsetBox[6, {4.2, 9.4}, {0, 1.5}], InsetString]},
Frame->True,
FrameLabel->{
FormBox[Spring deflection [mm], TraditionalForm],
FormBox[Spring force [kN], TraditionalForm]},
FrameTicks->{{{0,
FormBox[0, TraditionalForm]}, {2,
FormBox[2, TraditionalForm]}, {4,
FormBox[4, TraditionalForm]}, {6,
FormBox[6, TraditionalForm]}, {8,
FormBox[8, TraditionalForm]}, {10,
FormBox[10, TraditionalForm]}, {12,
FormBox[12, TraditionalForm]}, {14,
FormBox[14, TraditionalForm]}}, {{0,
FormBox[0, TraditionalForm]}, {5,
FormBox[5, TraditionalForm]}, {10,
FormBox[10, TraditionalForm]}, {15,
FormBox[15, TraditionalForm]}, {20,
FormBox[20, TraditionalForm]}, {25,
FormBox[25, TraditionalForm]}}, None, None},
ImageSize->Large,
PlotRange->{{-4, 14}, {-5, 30.}},
PlotRangeClipping->True,
PlotRangePadding->{Automatic, Automatic},
Prolog->InsetBox[
BoxData[
FormBox[
TagBox[
GridBox[{{
Spring force [kN]}, {
RowBox[{-, 1000.`}],
RowBox[{-, 1000.`}], 0.`}, {2, 1.4`, 1.`, 0.`},
{
3, 3.7`, 2.1`, 14.5`}, {
4, 4.5`, 2.9`, 14.4`}, {
5, 10.1`, 8.6`, 24.2`}, {
6, 4.2`, 2.6`, 14.4`}},
GridBoxAlignment -> {
Columns -> {{Center}}, Rows -> {{Center}}},
GridBoxDividers -> {
Columns -> {{True}},
Rows -> {True, False, True, {False}, True}},
GridBoxItemSize -> {Columns -> {
Scaled[0.03],
Scaled[0.1],
Scaled[0.1],
Scaled[0.2]}, Rows -> {{Automatic}}}, ColumnsEqual -> False,
RowsEqual -> False,
GridBoxSpacings -> {
Columns -> {{1}}, Rows -> {1, 1, 1, {0}, 1}},
BaseStyle -> {FontFamily -> Arial, FontSize -> 9}],
Grid], TraditionalForm]],
Scaled[{1, 0.14285714285714285`}],
Scaled[{1.05, -0.1}],
Scaled[{1, 1}]]])
===
Subject: Re: Graphics export to BMP and JPEG
why, please tell me WHY, *W_H_Y* do you export a bitmap
when you have a vector graphic ?
For an ordianry Plot[] result the vector graphic
has a smaller file size can printed in any resolution.
It is hopeless to make a bitmap because your screen has
ca 72 dpi, a medium quality printer 600 dpi and your eye
2200 dpi .. you will never have the right size/resolution.
Jens
> Hello all,
what options are recommended for
> Export[image.bmp,_Graphics,ImageSize->..,ImageResolution->..], also
> for image.jpg, image.tiff in order to get image files of the same
> quality as right mouse clicking the image in the notebook and copying
> as a bitmap or metafile? I tried different values of ImageSize-
>> ..,ImageResolution->.. but with quite poor results. The _Graphics
> were ordinary plots created by Plot or ListPlot.
For example, Export[image.bmp,_Graphics,ImageSize-
>> Large,ImageResolution->72 n] with n=1,2,3,... did not improve the
> image quality with increasing n. I checked with Irfan view that with
> increasing ImageResolution the default print size of the image
> decreased proportionally. In other words, the image resolution at
> constant image size remained always constant (and poor).
Increasing ImageSize at constant ImageResolution increased
> proportionally both the default print size and the number of pixels as
> one would expect. But artificially exporting the graphics with large
> ImageSize and then sizing down does not help as the text size remains
> constant during the export even when ImageSize increases and thus
> sizing down subsequently would make the text invisible.
As a side question, what are the default sizes for ImageSize->Large,
> Medium or Small in different situations? Are they documented
> somewhere?
Hannes Kessler
===
Subject: Re: FullSimplify in functions
Michael Mandelberg
===
Subject: Re: Plotting x and y arrays
>I have a table of x values and a separate table of corresponding y
>values. Is there a way to plot these values directly without using
>MapThread and without creating a new table to store the x and y
>values?
ListPlot[Transpose@{x,y}]
--
To reply via email subtract one hundred and four
===
Subject: Re: Plotting x and y arrays
This will do the sort of thing that you want:
x = RandomReal[{-1, 1}, {100}];
y = RandomReal[{-1, 1}, {100}];
ListPlot[Transpose[{x, y}]]
--
Steve Luttrell
West Malvern, UK
>I have a table of x values and a separate table of corresponding y values.
>Is there a way to plot these values directly without using MapThread and
>without creating a new table to store the x and y values?
> John
>
===
Subject: Re: Plotting x and y arrays
> I have a table of x values and a separate table of corresponding y values.
Is there a way to plot these values directly without using MapThread and
without creating a new table to store the x and y values?
John
>
Say xvals ans yvals are two tables that contain the x and y values,
respectively. Then you can use
ListPlot[Transpose[{xvals, yvals}]]
to plot the data. For instance,
xvals = RandomReal[{0, 5}, {20}]
yvals = Sin@xvals
ListPlot[Transpose[{xvals, yvals}], Filling -> Axis]
HTH,
--
Jean-Marc
===
Subject: Re: Plotting x and y arrays
xData = Table[x, {x, 0, Pi, Pi/1024.}];
yData = Sin /@ xData;
ListPlot[Transpose[{xData, yData}]]
but Transpose[{xData, yData}]
is a new table
Jens
> I have a table of x values and a separate table of corresponding y values.
Is there a way to plot these values directly without using MapThread and
without creating a new table to store the x and y values?
John
>
===
Subject: Can't calculate numerical derivative of EllipticTheta
I realize that my version of Mathematica is getting a little old. Is
this fixed in later releases?
In[1]:= $Version
In[2]:= pdf[x_,x0_,sig_] := 1/(Sqrt[2Pi]sig) Exp[-(x-x0)^2/(2sig^2)];
In[3]:= Sum[pdf[x,0,sig],{x,-Infinity,Infinity}]
2
-1/(2 sig )
EllipticTheta[3, 0, E ]
Out[3]= ---------------------------------
Sqrt[2 Pi] sig
In[4]:= f[sig_]=%;
In[5]:= f'[1.]
(0,0,1)
Out[5]= -1. + 0.241971 EllipticTheta [3, 0, 0.606531]
I expected to see a number on this last line.
Scott
--
Scott Hemphill hemphill@alumni.caltech.edu
This isn't flying. This is falling, with style. -- Buzz Lightyear
===
Subject: Re: Can't calculate numerical derivative of EllipticTheta
> I realize that my version of Mathematica is getting a little old. Is
> this fixed in later releases?
> In[1]:= $Version
In[2]:= pdf[x_,x0_,sig_] := 1/(Sqrt[2Pi]sig) Exp[-(x-x0)^2/(2sig^2)];
> In[3]:= Sum[pdf[x,0,sig],{x,-Infinity,Infinity}]
> 2
> -1/(2 sig )
> EllipticTheta[3, 0, E ]
> Out[3]= ---------------------------------
> Sqrt[2 Pi] sig
> In[4]:= f[sig_]=%;
> In[5]:= f'[1.]
> (0,0,1)
> Out[5]= -1. + 0.241971 EllipticTheta [3, 0, 0.606531]
> I expected to see a number on this last line.
> Scott
> --
> Scott Hemphill hemphill@alumni.caltech.edu
> This isn't flying. This is falling, with style. -- Buzz Lightyear
>
You can get correct numerical answer by using instead of f'[1.]
N[f'[1],10]
0.0193719
Note that simply N[f'[1]] will not work. This is reasonable because
using MachinePrecision would not produce an accurate answer. You can
see this by defining your function in a somewhat different way.
Replace your definition
f[sig_]=%
with
f[sig_?NumericQ] = %;
Now you can differenitate numerically (but not in Mathematica 6 !)
f'[1.]
-2.115267372136438*^-7
The only problem is that this answer is clearly wrong. This is due to
numerical instability of this problem which makes it unsuited to
using MachinePrecision numbers.
Andrzej Kozlowski
===
Subject: Re: Can't calculate numerical derivative of EllipticTheta
> I realize that my version of Mathematica is getting a little old. Is
> this fixed in later releases?
In[1]:= $Version
> In[2]:= pdf[x_,x0_,sig_] := 1/(Sqrt[2Pi]sig) Exp[-(x-x0)^2/(2sig^2)];
In[3]:= Sum[pdf[x,0,sig],{x,-Infinity,Infinity}]
2
> -1/(2 sig )
> EllipticTheta[3, 0, E ]
> Out[3]= ---------------------------------
> Sqrt[2 Pi] sig
In[4]:= f[sig_]=%;
In[5]:= f'[1.]
(0,0,1)
> Out[5]= -1. + 0.241971 EllipticTheta [3, 0, 0.606531]
I expected to see a number on this last line.
As far as I see in vs 6.01 the numerical part of elliptic functions and
the differentiation wrt the index for many other indexed families of
functions is not implemented too far.
In this case the result is a fourier series
http://functions.wolfram.com/EllipticFunctions/EllipticTheta3/20/01/02/
--
Roland Franzius
===
Subject: Mathematica not considering an assumption
Assuming[a < 0,Integrate[x^a, {x, 5, 6}]}]
This Integral, for a = -1, is equal to Log(6/5)
Why doesn't Mathematica report it?
Leonardo
===
Subject: Re: Mathematica not considering an assumption
> Assuming[a < 0,Integrate[x^a, {x, 5, 6}]}]
> This Integral, for a = -1, is equal to Log(6/5)
> Why doesn't Mathematica report it?
[I'm using version 5.2, but that probably doesn't make any difference
here.]
First, if you replace a with -1 in the definite integral, it is hardly
surprising that Mathematica gets the answer we all expect:
In[6]:= Integrate[x^(-1), {x, 5, 6}]
Out[6]= Log[6/5]
It might also be worthwhile to note that
In[7]:= Assuming[a == -1, Integrate[x^a, {x, 5, 6}]]
Out[7]= Log[6/5]
Now, in your title, you seem concerned with Mathematica not considering
an
assumption. I can understand, perhaps, why you say that because both
Integrate[x^a, {x, 5, 6}] and Assuming[a < 0, Integrate[x^a, {x, 5, 6}]]
produce the same result, namely,
Out[9]= (-5^(1 + a) + 6^(1 + a))/(1 + a)
Thus, since your assumption, a < 0, did not affect the result, you seem to
have concluded that Mathematica was (incorrectly?) ignoring your
assumption. And I suppose you realize that merely replacing a with -1 in
Out[9] yields Indeterminate, rather than your desired Log[6/5].
But you need to ask yourself:
How could the result of Integrate[x^a, {x, 5, 6}] or
Assuming[a < 0, Integrate[x^a, {x, 5, 6}]] be improved?
One possibility which might occur to you is that the result should be given
using Piecewise so that, when a == -1, we get Log[6/5], and otherwise, we
get Out[9]. But does that constitute an improvement? You may think so,
while the people at Wolfram Research (and other CASs, for that matter)
might disagree.
Another possibility, due to the fact that the singularity in Out[9] is
removable, is that the result could be given as
Limit[(-5^(1 + u) + 6^(1 + u))/(1 + u), u -> a]
But again we must ask if that would constitute an improvement or not.
David W. Cantrell
===
Subject: Re: Mathematica not considering an assumption
Hello Leonardo,
You can try on of the following:
a = -1; Assuming[a < 0, Integrate[x^a, {x, 5, 6}]]
or
Assuming[a == -1, Integrate[x^a, {x, 5, 6}]]
and you should have the integration result you are looking for
(Log[6/5]).
I have tried both of them and got the same result (Log[6/5]).
===
Subject: Re: Mathematica not considering an assumption
> Assuming[a < 0,Integrate[x^a, {x, 5, 6}]}]
------------------------------------------^
Syntax error: extraneous curly bracket.
> This Integral, for a = -1, is equal to Log(6/5)
Why doesn't Mathematica report it?
Usually, functions like *Integrate* return the most general solution,
solution applicable in most cases, without returning any constants of
integration or restrictions on the domain or special cases. For
instance, integrating 1/x just return the antiderivative Log[x], which
obviously does not work for x == 0 (or x < 0 if we restrict ourself to
the reals).
In[1]:= Integrate[1/x, x]
Out[1]= Log[x]
In[2]:= Assuming[a < 0, Integrate[x^a, {x, 5, 6}]]
Out[2]= (-5^(1 + a) + 6^(1 + a))/(1 + a)
In[3]:= Limit[%, a -> -1, Direction -> -1]
Out[3]= Log[6/5]
In[4]:= Limit[%, a -> -1, Direction -> +1]
Out[4]= Log[6/5]
In[5]:= Integrate[x^(-1), {x, 5, 6}]
Out[5]= Log[6/5]
--
Jean-Marc
===
Subject: Re: Mathematica not considering an assumption
In Mathematica 6.0.1
Assuming[a < 0, Integrate[x^a, {x, 5, 6}]]
Limit[%, a -> -1] gives
(-5^(1 + a) + 6^(1 + a))/(1 + a)
Log[6/5]
--
David Park
djmpark@comcast.net
http://home.comcast.net/~djmpark/
> Assuming[a < 0,Integrate[x^a, {x, 5, 6}]}]
This Integral, for a = -1, is equal to Log(6/5)
Why doesn't Mathematica report it?
> Leonardo
>
>
===
Subject: Re: New LevinIntegrate package for highly oscillatory integration
I would like to have an explanation of this so called so that other people
know the limits of their rights. It is filling in for other people and they
did not even say anything yet.
The benevolent attitude to people exists everywhere. Also the people who see
that a human is a dangerous animal.
I am thankful for those initiatives which just give. And I do not like
systems nor arguments which are negative to these initiatives. I cite as an
example for what I see as benevolent, the 100$ PC from Nicholas Negroponte.
Many people have the same attitude on a smaller scale.
with friendly greetings,
P_ter
===
Subject: Tooltip does not what I expect it to do
I get the same thing here, with WinXP, Mathematica v6.01; Tooltip doesn't
work in the first example.
Bobby
> why does this not work?
> ListPlot[Tooltip[{{1, 3}}, een]]?
> And this does: ListPlot[Tooltip[{{1, 3}}, een], PlotRange -> Full]
> I restarted Mathematica V6.01 on my MacBookPro, but it did not help. Any
> idea?
> with friendly greetings,
> P_ter
>
--
DrMajorBob@bigfoot.com
===
Subject: Re: Tooltip does not what I expect it to do
Hi - Both of them are working fine, and using the function PlotRange
does not make any difference.
===
Subject: Tooltip does not what I expect it to do
Peter,
This appears to be a bug or undocumented feature.
Only
ListPlot[Tooltip[{{1, 3}}, een], PlotRange -> Full] displays the
tooltip.
None of the other options for PlotRange work.
ListPlot[Tooltip[{{1, 3}}, een], PlotRange -> Automatic]
ListPlot[Tooltip[{{1, 3}}, een], PlotRange -> {{0., 2.}, {0., 6.}}]
ListPlot[Tooltip[{{1, 3}}, een], PlotRange -> {0., 6.}]
ListPlot[Tooltip[{{1, 3}}, een], PlotRange -> 6.]
Syd Geraghty B.Sc., M.Sc.
sydgeraghty@mac.com
San Jose, CA
My System
Mathematic 6.0.1 for Mac OS X x86 (32 - bit) (June 19, 2007) License
L2983-5890
MacOS X V 10.4 .10
> why does this not work?
> ListPlot[Tooltip[{{1, 3}}, een]]?
> And this does: ListPlot[Tooltip[{{1, 3}}, een], PlotRange -> Full]
> I restarted Mathematica V6.01 on my MacBookPro, but it did not
> help. Any idea?
> with friendly greetings,
> P_ter
>
===
Subject: Re: Errant post?
Daniel,
clickCoordinateList[g_Graphics]:=DynamicModule[{pts = {}},
Column[
{ClickPane[
Dynamic@Show[g,
Graphics[{Black, Point /@ pts}]], (pts = Append[pts, #]) &],
StyleForm[
nStart clicking on the graph above. The list below will grow,
with one new x-y coordinate pair for each click. When you're done,
highlight the list from just before the first brace to just past the
last one. Next, use Edit/Copy on the front end menu bar to put the
list on the clipboard. Then you can Edit/Paste the list into a new
input cell for further manipulation. If you highlight much beyond
the list, you'll just get a string with the name of the internal
coordinate list variable (pts$$) when you paste into a new cell,
rather than the coordinates themselves. nn You may find it useful
to copy this function into the init.m file in the
$UserBaseDirectory/Kernel subdirectory so it's available every time
you start Mathematica.n, FontFamily -> Helvetica, FontSize -> 12,
FontWeight -> Bold, FontColor -> Red],
Dynamic[pts]}]]
Here's an example of how to use this function:
gMyGraph=Plot[Sin[x]/x,{x,-10,10},GridLines->Automatic,Frame->True]
clickCoordinateList[Show[gMyGraph,ImageSize->500]]
pastedPoints=**** paste list from above here ****;
deltas=Rest[pastedPoints]-Most[pastedPoints];
approximatePathLength=Plus@@(Sqrt[#.#]&/@deltas)
---Joe DeWitte
===
Subject: Show and scaling
I want to plot a 3d surface with 3d spheres lying on it. Therefore I
use
Show[myPlot3D, Graphics3D[Sphere[coord]].
Unfortunately, the spheres becomes scaled down in their z-coordinate
and thus look flat like disks. How can I avoid the scaling of the
Graphics3D objects?
M.
===
Subject: Why is NonCommutativeMultiply Protected?
Why is NonCommutativeMultiply Protected?
Is it safe to redefine NonCommutativeMultiply? Does it have any special
built-in properties (apart from being Flat and OneIdentity)? Is it used
by any of the built-in functions?
NonCommutativeMultiply certainly does not evaluate to anything, but the
same can be said about Rule[], which is not at all safe to redefine
because: 1. It has some special properties (it affects scoping, it does
not like Unevaluated[], etc.) 2. It is used together with functions
such as Replace, and (most probably) built-in functions use it internally.
So is it safe to Unprotect[NonCommutativeMultiply] and attach
definitions to it? (I know that in certain situations one can use
UpValues, but I would like to know the answer to this question.)
--
Szabolcs
===
Subject: Re: Re: What am I doing wrong with this code?
But extra value from Premier Service aside from upgrades IS available:
- top-priority access to tech support
- a 2nd, home-use license for Mathematica
- copy of webMathematica Amateur
- copy of Wolfram Workbench
- discounts on some application packages
- discounts at Wolfram conferences,etc.
> I think it's cheaper to buy the Premier Service, which includes free
> upgrades, rather than buy them as they come. That way, you don't have to
> worry about when upgrades will occur.
OTOH, I've gotten no noticeable value from P.S. OTHER than the upgrades.
--
Murray Eisenberg murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
===
Subject: Re: What am I doing wrong with this code?
I think it's cheaper to buy the Premier Service, which includes free
upgrades, rather than buy them as they come. That way, you don't have to
worry about when upgrades will occur.
OTOH, I've gotten no noticeable value from P.S. OTHER than the upgrades.
Bobby
> imaginary nujmbers. It's great that new v6.0 can plot this these
> functions. Maybe it's time to upgrade for me also.
> I just didn't want another new versions to come out as soon as I
> upgrade(happened last time). Anyone know when the v 6.1 or 6.2 or
> 6.3 is due to be released?
--
DrMajorBob@bigfoot.com
===
Subject: Re: What am I doing wrong with this code?
> imaginary nujmbers. It's great that new v6.0 can plot this these
> functions. Maybe it's time to upgrade for me also.
There is nothing special about version 6. Mathematica 5.2 plots these
functions too, it just issues a warning message, which can be turned off
with
Off[Plot::plnr]
In Mathematica 6, this warning message cannot be turned on at all!
> I just didn't want another new versions to come out as soon as I
> upgrade(happened last time). Anyone know when the v 6.1 or 6.2 or
> 6.3 is due to be released?
--
Szabolcs
===
Subject: Export from windows to linux/unix
Often times I am using Mathematica (running on windows desktop) to
generate a large number of input files for batch jobs on a linux based
cluster.
Is there a way to get Export to automatically remove those pesky end-
of-line carriage returns?
I have been using dos2unix command...does Mathematica have an on-board
solution for this issue?
Jeremy
===
Subject: Export option examples. Saving an image with a palette.
I am trying to export a 2D graphic (made with a bunch of insets) to a BMP
file, but it needs to use a specific palette.
Obvioulsy I could rasterize and then take the element and make them indices
and then save the final reult using export, but is there a built-in way to
specify the palette on export?
I find the documentation confusing because it mixes information about Import
and Export. It is a bummer that there are so few examples.
Luc
===
Subject: Re: Ordering function weird?
>See the example below. I totally expect and want the result of
>Ordering[x]. But I neiter understand nor expect the result of
>Ordering[y]. Both Sort[x] and Sort[y] are ok. Can anybody explain to
>In[3]:= x = {1, 2, 3, 6, 10, 3, 4} y = {1, 2, 7, 8, 9, 1, 2}
>In[7]:= Ordering[x] Ordering[y]
>Out[7]= {1, 2, 3, 6, 7, 4, 5}
>Out[8]= {1, 6, 2, 7, 3, 4, 5}
I don't understand your confusion. Looking at y I see the
smallest value in position 1 with the same value in position 6.
Hence the first two elements of the output. Then the next
smallest values are in position 2 and 7. So, the first 4 items
should be {1,6,2,7}. The largest 3 values occur in order from
positions 3 to 5. So, the output should be {1,6,2,7,3,4,5} as is
the case. What were you expecting?
--
To reply via email subtract one hundred and four
===
Subject: Solving Inequality
My friend has the following code to solve a system of nonlinear inqualities.
She can run it on her laptop. However, when I run on my laptop there was a
message saying that 0.1 is not a variable. Where 0.1 is the valua that
was initially assigned to an unknown parameter in the inquality system. I
would highly appreciate if you can explain why this might be the case.
Quang
Here is the code:
<< Algebra`InequalitySolve`
c2 = 580
c3 = 600
b1 = 50
c1 = 400
d1 = 100
p1 = .1
r1 = .3
a2 = 400
b2 = 300
d2 = 50
p2 = .9
r2 = .7
[Alpha]1 = .1
[Alpha]2 = .2
[Alpha]3 = .3
[Alpha]4 = .4
[Alpha]5 = .5
[Alpha]6 = .6
[Alpha]7 = .7
[Alpha]8 = .8
[Alpha]9 = .9
[Alpha]10 = 1
[Alpha]11 = 1.1
[Alpha]12 = 1.2
[Alpha]13 = 1.3
[Alpha]14 = 1.4
[Alpha]15 = 1.5
(*0-15*)
a1 = 30
a3 = 680
b = 0
[Gamma] = 0.1
InequalitySolve[{a1^[Alpha]1*(Exp[-(-Log[p1])^[Gamma]]) +
b1^[Alpha]1*(1 - Exp[-(-Log[p1])^[Gamma]]) <
c1^[Alpha]1*(Exp[-(-Log[r1])^[Gamma]]) +
d1^[Alpha]1*(1 - Exp[-(-Log[r1])^[Gamma]]),
a3^[Alpha]1*(Exp[-(-Log[p1])^[Gamma]]) +
b1^[Alpha]1*(1 - Exp[-(-Log[p1])^[Gamma]]) >
c1^[Alpha]1*(Exp[-(-Log[r1])^[Gamma]]) +
d1^[Alpha]1*(1 - Exp[-(-Log[r1])^[Gamma]]),
a2^[Alpha]1*(Exp[-(-Log[p2])^[Gamma]]) +
b2^[Alpha]1*(1 - Exp[-(-Log[p2])^[Gamma]]) >
c2^[Alpha]1*(Exp[-(-Log[r2])^[Gamma]]) +
d2^[Alpha]1*(1 - Exp[-(-Log[r2])^[Gamma]]),
a2^[Alpha]1*(Exp[-(-Log[p2])^[Gamma]]) +
b2^[Alpha]1*(1 - Exp[-(-Log[p2])^[Gamma]]) <
c3^[Alpha]1*(Exp[-(-Log[r2])^[Gamma]]) +
d2^[Alpha]1*(1 -
Exp[-(-Log[r2])^[Gamma]])}, {[Gamma], [Alpha]1, b}]
===
Subject: NSolve keeps on running forever
Hi Guys,
I have a system of equations that I want to solve.It has a
solution but NSolve seems to keep on running forever.I am pasting the code
over here:
h[y_,t_,[Beta]0_,[Beta]1_,[Beta]2_,[Beta]3_,[Sigma]_,[Gamma]_]:={
{v[y,t,[Beta]0,[Beta]1,[Beta]2,[Beta]3,[Sigma],[Gamma]]},{(y[[t-1
]])*v[y,t,[Beta]0,[Beta]1,[Beta]2,[Beta]3,[Sigma],[Gamma]]},{((y[
[t-1]])^2)*v[y,t,[Beta]0,[Beta]1,[Beta]2,[Beta]3,[Sigma],[Gamma]]
},{(((v[y,t,[Beta]0,[Beta]1,[Beta]2,[Beta]3,[Sigma],[Gamma]])^2)-
[Sigma]^2*((y[[t-1]])^3))},{(((v[y,t,[Beta]0,[Beta]1,[Beta]2,[Beta]
3,[Sigma],[Gamma]])^2)-[Sigma]^2*((y[[t-1]])^3))*y[[t-1]]},{(((v[y,t,
[Beta]0,[Beta]1,[Beta]2,[Beta]3,[Sigma],[Gamma]])^2)-[Sigma]^2*(
(y[[t-1]])^3))*((y[[t-1]])^3)}};
v[y_,t_,[Beta]0_,[Beta]1_,[Beta]2_,[Beta]3_,[Sigma]_,[Gamma]_]:=
y[[t]]-y[[t-1]]-[Beta]0-[Beta]1*y[[t-1]]-[Beta]2*((y[[t-1]])^2);
hca[A_,c_,t_,y_,[Beta]0_,[Beta]1_,[Beta]2_,[Beta]3_,[Sigma]_,[Ga
mma]_]:=(
A.h
[y,t,[Beta]0,[Beta]1,[Beta]2,[Beta]3,[Sigma],[Gamma]])*w[A,c,t,y
,[Beta]0,[Beta]1,[Beta]2,[Beta]3,[Sigma],[Gamma]];
w[A_,c_,t_,y_,[Beta]0_,[Beta]1_,[Beta]2_,[Beta]3_,[Sigma]_,[Gamm
a]_]:=
Min[1,c/Norm[A.h
[y,t,[Beta]0,[Beta]1,[Beta]2,[Beta]3,[Sigma],[Gamma]]]];
*c=5.85;
A={{a11,a12,a13,a14,a15,a16},{a21,a22,a23,a24,a25,a26},{a31,a32,a33,a34,a35,
a36},{a41,a42,a43,a44,a45,a46},{a51,a52,a53,a54,a55,a56},{a61,a62,a63,a64,a65
,a66}};
y={1,2,3,2,1,4,5,3,2,1};
NSolve[{!(
*UnderoverscriptBox[([Sum]), (h = 2), (Length[y])]hca[A, c,
h, y,
[Beta]0, [Beta]1, [Beta]2, [Beta]3, [Sigma],
[Gamma]])=={{0},{0},{0},{0},{0},{0}},
1/Length[y]*(!(
*UnderoverscriptBox[([Sum]), (s = 2), (Length[y])]hca[A, c,
s, y,
[Beta]0, [Beta]1, [Beta]2, [Beta]3, [Sigma], [Gamma]] .
Transpose[hca[A, c, s, y, [Beta]0, [Beta]1, [Beta]2, [Beta]3,
[Sigma],
[Gamma]]]))=={{1,0,0,0,0,0},{0,1,0,0,0,0},{0,0,1,0,0,0},{0,0,0,1,0,0},{0
,0,0,0,1,0},{0,0,0,0,0,1}}},{[Beta]0,[Beta]1,[Beta]2,[Beta]3,[Sigma
],[Gamma]}]
Nabeel*
--
Nabeel Butt
UWO,London
Ontario, Canada
===
Subject: Plotting an explicit solution!
Hello everybody,
* I have this explicit solution:
z== (x^2 + z^2)^(3/2) - (z + x + x Cos[y])^(5/2)
* As you see it has three variables: x,y and z.
* I have ploted it by using the function ContourPlot3D:
ContourPlot3D[z == (x^2 + z^2)^(3/2) - (z + x + x Cos[y])^(5/2),
{x, 1, 50}, {y, 0, [Pi]/2}, {z, 0, 3}]
I am just wondering if using the function ContourPlot3D was correct
in this such a peoblem, or should I use another function!
Mark
===
Subject: How to use Fourier (fft) to solve eplliptic partial differential
equation?
Does's anyone how to use Fourier (fft) function in mathematica to
solve eplliptic partial differential equation? It's a pseudospectal
method.
Dave
===
Subject: Re: Re: Gradient of a List
min and max aren't defined in that piece of code. It's from a notebook
that starts with my earlier solution:
data = Table[{x + RandomReal[], Sin@x + 0.1 RandomReal[]}, {x, 0, Pi,
0.1}];
f = Interpolation[data, InterpolationOrder -> 3];
{min, max} = data[[Ordering[data][[{1, -1}]], 1]];
Quiet@Plot[f'[x], {x, min, max}, PlotRange -> All]
which defined min and max broad enough, apparently, to work with the other
code and new data. I'd forgotten to reset min and max whenever the data
changes, and I wasn't getting error messages, so...
Sorry for the confusion.
Bobby
> Bobby,
> There is something amiss in the line
> Plot[g[data, 0.5]'[x], {x, min, max}, PlotRange -> All]
> below. I have been trying different fixes for ten minutes but have not
> succeeded so I thought I would ask your help.
Syd Geraghty B.Sc., M.Sc.
> sydgeraghty@mac.com
> San Jose, CA
> My System
> MacOS X V 10.4 .10
> Scott,
> I hadn't noticed I was perturbing the x-values and using UNperturbed x
>> to
>> calculate y. No wonder the result looked so awful!
> Your Gaussian smoothing works amazingly well in this situation.
> I think I'd write it this way, however:
> ClearAll[pdf, g, x, data]
>> pdf[xIdeal_, sig_] = Exp[-((# - xIdeal)/sig)^2/2]/(Sqrt[2 Pi] sig) &;
>> g[data_, sigma_] := g[data, sigma] = Function[{x},
>> Evaluate@Block[{x0, y0},
>> {x0, y0} = Transpose@data;
>> y0.Normalize[pdf[x, sigma] /@ x0, Total]]]
> data = Table[{x + RandomReal[], Sin@x + 0.1 RandomReal[]}, {x, 0, Pi,
>> 0.1}];
>> Plot[g[data, 0.5]'[x], {x, min, max}, PlotRange -> All]
> Notice the just-in-time definition of g.
> Bobby
> data = Table[{x + RandomReal[], Sin@x + 0.1 RandomReal[]}, {x, 0, Pi,
>> 0.1}];
>> f = Interpolation[data, InterpolationOrder -> 3];
>> {min, max} = data[[Ordering[data][[{1, -1}]], 1]];
>> Quiet@Plot[f'[x], {x, min, max}, PlotRange -> All]
> I use Quiet because Plot sometimes samples outside the data range and
>> throws the InterpolatingFunction::dmval message.
> Notice, however, the result isn't even close to Cos[x], and it changes
>> quite a bit if you change the InterpolationOrder.
> Of course, these problems are because of the noise in both the x and y
> data values. Since Interpolation insists on passing exactly through
> the points given, the interpolating function has to wiggle around a
> lot to fit all the noise. The OP may not have any noise in his
> independent variables (x,y) and may have little or none in his
> function values.
> Still, yours is an interesting problem. One way of handling it would
> be to interpolate via weighted averages. For example, you could
> assign a Gaussian weight to all the function values based on how close
> the x value is to the x coordinates of the data:
> (* Gaussian centered at x0, with standard deviation sig *)
> pdf[x_,x0_,sig_] := 1/(Sqrt[2Pi]sig) Exp[-(x-x0)^2/(2sig^2)];
> (* Gaussian weighted average of data, using sig = 0.5 *)
> (* try using other values for sig *)
> g[x_] = Block[{x0,y0,w},
> x0 = data[[All,1]]; (* x-coordinates of data *)
> y0 = data[[All,2]]; (* y-coordinates of data *)
> w = pdf[x,#,0.5]& /@ x0; (* weight the x-coordinates *)
> w /= Plus @@ w; (* Normalize the weights *)
> w . y0 (* Return interpolated function value *)
> ];
> Now you have a continuous function g[x], and you can plot it as well
> as g'[x]. (Of course it is inefficient, since it recalculates all the
> weights every time you call it. You could enter foo[x_]g[x]; and
> then foo[x] wouldn't have that problem.)
> One nice feature of Gaussian weights happens if you have a set of
> equally spaced data points. If they extend infinitely in both
> positive and negative directions, or *equivalently* the function
> values are zero beyond the region of interest, then you can omit the
> normalization step. (One example is in image processing, where the
> region beyond the boundaries of the image may be assumed to be black.)
> Then the Gaussian weighting is equivalent to convolution(1) with a
> Gaussian kernel. This convolution has some nice properties. For
> example, it is infinitely differentiable, because the Gaussian is.
> Also, you can express its derivatives in the same form as the
> convolution itself, i.e. the convolution of a Gaussian with a set of
> data points.
> The OP might be able to use the two-dimensional version of the the
> Gaussian weighted interpolation above, but Mathematica's built-in
> polynomial interpolation might work perfectly well.
> (1) when I speak of convolution with a data point (x0,y0), I really
> mean convolving with the function y0*DiracDelta[x0]. The result
> is a y0 times a Gaussian centered at x0. Convolution with a
> collection of data points gives the sum of all the Gaussians.
>> Hi everybody,
>>> Does anybody know how can I get the gradient of a list of points
?
>>> My real problem is:
>>> I have a scalar field previously obtained numerically that for a
> given point (xi,yi) takes a value f(xi,yi). What I want to do is an
> estimation of the gradient of this scalar field BUT I haven't got any
> analytical function that expresses my field so I can't use the Grad
> function.
>>> How can I solve this using Mathematica?
>>> Olalla, Bilbao UPV/EHU
>>> --
> DrMajorBob@bigfoot.com
>>> --
>> DrMajorBob@bigfoot.com
>
--
DrMajorBob@bigfoot.com
===
Subject: Re: Gradient of a List
Scott,
I hadn't noticed I was perturbing the x-values and using UNperturbed x to
calculate y. No wonder the result looked so awful!
Your Gaussian smoothing works amazingly well in this situation.
I think I'd write it this way, however:
ClearAll[pdf, g, x, data]
pdf[xIdeal_, sig_] = Exp[-((# - xIdeal)/sig)^2/2]/(Sqrt[2 Pi] sig) &;
g[data_, sigma_] := g[data, sigma] = Function[{x},
Evaluate@Block[{x0, y0},
{x0, y0} = Transpose@data;
y0.Normalize[pdf[x, sigma] /@ x0, Total]]]
data = Table[{x + RandomReal[], Sin@x + 0.1 RandomReal[]}, {x, 0, Pi,
0.1}];
Plot[g[data, 0.5]'[x], {x, min, max}, PlotRange -> All]
Notice the just-in-time definition of g.
Bobby
>> data = Table[{x + RandomReal[], Sin@x + 0.1 RandomReal[]}, {x, 0, Pi,
>> 0.1}];
>> f = Interpolation[data, InterpolationOrder -> 3];
>> {min, max} = data[[Ordering[data][[{1, -1}]], 1]];
>> Quiet@Plot[f'[x], {x, min, max}, PlotRange -> All]
> I use Quiet because Plot sometimes samples outside the data range and
>> throws the InterpolatingFunction::dmval message.
> Notice, however, the result isn't even close to Cos[x], and it changes
>> quite a bit if you change the InterpolationOrder.
> Of course, these problems are because of the noise in both the x and y
> data values. Since Interpolation insists on passing exactly through
> the points given, the interpolating function has to wiggle around a
> lot to fit all the noise. The OP may not have any noise in his
> independent variables (x,y) and may have little or none in his
> function values.
> Still, yours is an interesting problem. One way of handling it would
> be to interpolate via weighted averages. For example, you could
> assign a Gaussian weight to all the function values based on how close
> the x value is to the x coordinates of the data:
> (* Gaussian centered at x0, with standard deviation sig *)
> pdf[x_,x0_,sig_] := 1/(Sqrt[2Pi]sig) Exp[-(x-x0)^2/(2sig^2)];
> (* Gaussian weighted average of data, using sig = 0.5 *)
> (* try using other values for sig *)
> g[x_] = Block[{x0,y0,w},
> x0 = data[[All,1]]; (* x-coordinates of data *)
> y0 = data[[All,2]]; (* y-coordinates of data *)
> w = pdf[x,#,0.5]& /@ x0; (* weight the x-coordinates *)
> w /= Plus @@ w; (* Normalize the weights *)
> w . y0 (* Return interpolated function value *)
> ];
> Now you have a continuous function g[x], and you can plot it as well
> as g'[x]. (Of course it is inefficient, since it recalculates all the
> weights every time you call it. You could enter foo[x_]=g[x]; and
> then foo[x] wouldn't have that problem.)
> One nice feature of Gaussian weights happens if you have a set of
> equally spaced data points. If they extend infinitely in both
> positive and negative directions, or *equivalently* the function
> values are zero beyond the region of interest, then you can omit the
> normalization step. (One example is in image processing, where the
> region beyond the boundaries of the image may be assumed to be black.)
> Then the Gaussian weighting is equivalent to convolution(1) with a
> Gaussian kernel. This convolution has some nice properties. For
> example, it is infinitely differentiable, because the Gaussian is.
> Also, you can express its derivatives in the same form as the
> convolution itself, i.e. the convolution of a Gaussian with a set of
> data points.
> The OP might be able to use the two-dimensional version of the the
> Gaussian weighted interpolation above, but Mathematica's built-in
> polynomial interpolation might work perfectly well.
> (1) when I speak of convolution with a data point (x0,y0), I really
> mean convolving with the function y0*DiracDelta[x0]. The result
> is a y0 times a Gaussian centered at x0. Convolution with a
> collection of data points gives the sum of all the Gaussians.
> Hi everybody,
> Does anybody know how can I get the gradient of a list of points?
> My real problem is:
> I have a scalar field previously obtained numerically that for a
>> given point (xi,yi) takes a value f(xi,yi). What I want to do is an
>> estimation of the gradient of this scalar field BUT I haven't got any
>> analytical function that expresses my field so I can't use the Grad
>> function.
> How can I solve this using Mathematica?
>> Olalla, Bilbao UPV/EHU
>>> --
> DrMajorBob@bigfoot.com
>>
--
DrMajorBob@bigfoot.com
===
Subject: how to draw a huffman tree
Hello all
I used Mathematica 5.2 for huffman coding. Now after i have codes, how
can properly draw a huffmna tree with these codes.
in mathematica 6. Is ther anyway to do it in
Mathematica 5.2?