mm-535
====
Subject: Re: Mathematica equivalent complexplot
> This is a newbie question, I suppose. I've read as much as I can but
cannot
> find a straight forward way to implement the complexplot in
> Mathematica 5.
>
> An example call could be complexplot(sin(x+i),x=-Pi..Pi) where sin(x+i)
> is a typical function f(x) that maps real to complex and -Pi..Pi is the
> domain of f, a..b. Of course, there are various plot options which can
> follow and would be included before the closing paren but I think I can
> handle that.
Hi Ron,
What you are looking for is the _ComplexMap_ standard add-on. The
following lines should help you to start with it (note we use pure
function to code sin(x + i) as Sin[#1 + I]&):
In[1]:=
Needs[Graphics`ComplexMap`]
In[2]:=
CartesianMap[Sin[#1 + I] & , {-Pi, Pi}, {-2, 2}];
In[3]:=
PolarMap[Sin[#1 + I] & , {-Pi, Pi}, {-2, 2}];
Also I would urge you to check David Park's _Cardano3_ package (and
indeed the whole web site which is full of outstanding add-ons for
Mathematica). Have a look at http://home.earthlink.net/~djmp/
/J.M.
====
Subject: Re: Reducing memory for big data sets
no, Mathematica use (at least) 32 bit integers and
there is no
data type for bytes, short int or what ever.
Jens
Maximilian Ulbrich
schrieb im Newsbeitrag
I have a big data set of 128*128*1000 points to
> evaluate (a series of
> images, and I plan to use 256*256*1000 as
> well...).
> When I read the data into Mathematica from text
> files, MemoryInUse[]
> says about 300MB are used. However, my images
> consist of only about
> 16.000.000 data points of 1 byte or 2 bytes for
> other data sets.
Is it possible to make Mathematica reduce the
> used memory by storing the
> data in another format maybe?
Max
>
====
Subject: Re: Applying function to nested lists
Kerry,
xlist = {{1, 2, 3}, {{4, 5, 6}, 7, 8}, 9};
Map[f, xlist, {-1}]
{{f[1], f[2], f[3]}, {{f[4], f[5], f[6]}, f[7], f[8]}, f[9]}
David Park
djmp@earthlink.net
http://home.earthlink.net/~djmp/
I'm trying to get Mathematica to do the following:
Suppose
x = {{1,2,3},{{4,5,6},7,8},9}
f = some function
How can I get f applied to each element of x but with the list structure
intact? I.e. I want something that generates:
{{f[1],f[2],f[3]},{{f[4],f[5],f[6]},f[7],f[8]},f[9]}
-Kerry Kim
====
Subject: Re: Re: Getting simple answers from Reduce, ComplexExpand and
FullSimplify
>ex = 2 Cos[z] + I a Sin[z];
>InputForm[Reduce[{0 == ex // TrigToExp, 0 < a < 1}, z]]
C[1] [Element] Integers && Inequality[0, Less, a, Less, 1] &&
>z == (-I/2)*((2*I)*Pi*C[1] + Log[(-2 + a)/(2 + a)])
Two points are interesting.
1. I used ComplexExpand on the output of Reduce and got a different
and
>incomprehensible answer compared to Andrzej Kozlowski and Pratik Desai who
>used ComplexExpand and TrigToExp, respectively, on the input to Reduce and
>got a simple answer. Is this obvious from the way Reduce works or does one
>get this by trial-and-error and tinkering? (I don't like tinkering I
don't
think you can really learn and understand by tinkering with computation.)
>
>
I beg to differ, you can learn a lot by tinkering, atleast you get a
feel for what the software is doing compared to what it is supposed to
do, your problem is a great example of it. I think what works for me is
to follow your intuition, just like solving it by hand , and once you
have enough experience you get better at it.
> 2. I note that Reduce sometimes generates a constant, C[1], that is
an
>element of the Integers and also has Im[C[1]] == 0. I know that there are
>Gaussian Integers but I would have thought that the definition of Integers
>in Mathematica would be restricted to real integers.
> Hugh Goyder
>
>Below the expression ex has roots, rts, where n in an integer and the
>>constant a is in the interval 0 < a <1. We may check this using
>>
>FullSimplify
>
>as follows.
>>ex=2 Cos[z]+I a Sin[z];
>>rts=z ->Pi(2n-1)/2 + I Log[(2+a)/(2-a)]/2;
>>FullSimplify[0 == ex/.rts,Element[n,Integers]]
>>My problem is to try and deduce the roots using computer algebra rather
>>
>than
>
>by hand. (I also have other expressions I would like to work on.) My
>>
>attempt
>
>at using Reduce is partially successful but leads to unfamiliar, and
>>difficult to interpret, ArcTanh functions
>>Reduce[{ex == 0,0>An attempt with FullSimplify and ComplexExpand to crack the ArcTanh
>>
>function
>
>is again partially successful in giving the imaginary part I require.
>>However, I am stuck with Arg functions with complex arguments. The Arg
>>Functions are just equal to -Pi/2 but I cannot crack them further. Any
>>suggestions for simplifying the output from Reduce so that I get the
>>
>simple
>
>form I guessed at the start? Alternativly, are there more methods for
>>simplifing the complex output?
>>FullSimplify[ComplexExpand[(2*I)*ArcTanh[a/2+(I/2)*Sqrt[4-a^2]]],{0>FullSimplify[ComplexExpand[Arg[2-a-I Sqrt[4-a^2]]-Arg[
>>2+a+I Sqrt[4-a^2]]],{0>Hugh Goyder
>>
>
>
--
Pratik Desai
Graduate Student
UMBC
Department of Mechanical Engineering
Phone: 410 455 8134
====
Subject: Beginner's Question on I/O Files for Raw Numerical Data
I'm looking for an economical way to make polar plots of the trajectories
of the nine planets, from a 'C' simulation I'm writing, and since Excel is
insufficient, I'm thinking of moving up to Mathematica. Can anybody tell
me if Mathematica can read and write lists of ascii data? And am I right
in assuming that there's no way to read and write .csv files (comma
separated values)?
====
Subject: Re: Attempt to generalize a constant
and opines (hope it is ok to state it here,) that as z increases from
.5 to .999, the ImplicitPlot finds a string of small islands along the
crest of the ridges. The
numerics approach z=1 but rounding errors will obfuscate the nice
mathematical ( top ridge) line.
This has since been partially obtained in FindRoot/ListPlot.
<< Graphics`ParametricPlot3D`;
<< Graphics`ImplicitPlot`;
F[t_, mu_] := mu*JacobiSN[t, mu^2];
Jaco = ParametricPlot3D[{mu, t, F[t, mu]}, {mu, 1, 3, .1}, {t, Pi/6,
2Pi, Pi/12}, AspectRatio -> Automatic] ;
Plane = Plot3D[.95, {mu, 1, 3}, {t, Pi/6, 2Pi}] ;
Show[Jaco, Plane] ;
data = Table[{mu /. FindRoot[F[t, mu] == 1, {mu, 1, 3}, MaxIterations
-> 100], t}, {t, Pi/6, 2Pi, Pi/96}];
ListPlot[data, Frame -> True, Axes -> False, PlotJoined -> True,
PlotRange -> {{0.95, 3.15}, Automatic}, Epilog ->
{AbsolutePointSize[4], Red, Point /@ Select[data, IntegerQ[6*#[[2]]/Pi]
&]}, PlotStyle -> Blue, ImageSize -> 360];
(* In a simpler example, y is a variable, x1 was a known constant at
the outset/beginning in parabolic relation, before being variablized or
generalized to x, x1-> x ; It generalizes parabola to an ellipse while
including a second parameter *)
G[x1_, y_] = x1^2 + x1* y + y^2 ;
Plot3D[G[x1, y], {y, -1.2, 1.2}, {x1, -1.2, 1.2}];
Impl = ImplicitPlot[G[x, y] == 1 , {x, -1.2, 1.2}, {y, -1.2,
1.2},AspectRatio -> Automatic];
dat = Table[{y /.
FindRoot[G[x1, y] == 1, {y, -1.2, 1.2}, MaxIterations -> 100],x1}, {x1,
-1.2, 1.2, .1}];
LP = ListPlot[dat, Frame -> True, Axes -> False, PlotJoined -> True,
PlotRange -> {{-1.2, 1.2}, Automatic}, Epilog -> {AbsolutePointSize[4],
Red,Point /@ Select[data, IntegerQ[6*#[[2]]/Pi] &]}, PlotStyle -> Blue,
ImageSize -> 360]; Show[Impl, LP];
(* Intersection of above Jacobi function and flat plane z =
1 intersection curves look like hyperbolae mu * t = constant. By
assembling ListPlot roots obtained from FindRoot either in the given
known ellipse case or in JacobiSN case we do not capture all of the
possible function points. Is the problem due to convergence?
branching? seed value location? -- Implicit Plot / Contour Plot was
expected to capture ALL the roots! *)
====
Subject: Re: Solve
Hi Rick,
Solve[] tries to get all solutions assuming that the variables and
coefficients are complexes. Therefore
In[1]:=
eqn = -0.13249751088801667 + 0.06632187456026009*r^1 +
0.06629492661634433*r^2 - 0.00005387198125569*
r^3 - 0.00002692675947693*r^4 +
1.324872853*^-8*r^5 + 4.3598855*^-9*r^6 -
3.7184*^-13*r^7 - 4.3768*^-13*r^8 + 1.72*^-15*r^9;
In[2]:=
answer = Solve[eqn == 1.83303, r]
Out[2]=
{{r -> -61.90357130844081 - 40.91171644953396*I},
{r -> -61.90357130844081 + 40.91171644953396*I},
{r -> -59.82559087206599},
{r -> -6.0000033545518106},
{r -> 4.999998407310261}, {r -> 73.55788661519043},
{r -> 82.3157609927675 - 32.39241011754585*I},
{r -> 82.3157609927675 + 32.39241011754585*I},
{r -> 200.90844611453358}}
In[3]:=
eqn /. Answer
Out[3]=
{1.83303000000015 - 5.684341886080802*^-14*I,
1.83303000000015 + 5.684341886080802*^-14*I,
1.8330300000000328, 1.8330300000000006,
1.8330300000000004, 1.8330299999997948,
1.8330300000008037 + 4.831690603168681*^-13*I,
1.8330300000008037 - 4.831690603168681*^-13*I,
1.833030000096187}
In[4]:=
Chop[%]
Out[4]=
{1.83303000000015, 1.83303000000015,
1.8330300000000328, 1.8330300000000006,
1.8330300000000004, 1.8330299999997948,
1.8330300000008037, 1.8330300000008037,
1.833030000096187}
the rules returned by Solve are all correct solutions up to a certain
degree of precision. Solve does not have any ideas about the
restrictions you want to impose to the variable r, corresponding to the
constraints of your model indeed, so it returns all nine solutions.
You can use Reduce to impose some condition on the variable r
In[5]:=
Reduce[{eqn == 1.83303, 0 <= r <= 16}, r]
Out[5]=
r == 4.999998407310261
although you will bet a warning message about the usage of non-exact
coefficients, or
In[6]:=
FindInstance[{eqn == 1.83303, 0 <= r <= 16}, r]
Out[6]=
{{r -> 4.999998407310261}}
====
Subject: Re: Solve
> I'm generating 9th degree polynomials with Mathematica
> from real world data. Then I'm using them in an
> application I'm writing in Xcode. This works
> beautifully!
I get an equation like...
-0.13249751088801668 + 0.06632187456026009*r^1
> +0.06629492661634432*r^2 - 0.00005387198125569*r^3
> -0.00002692675947693*r^4 + 0.00000001324872853*r^5
> +0.00000000435988550*r^6 - 0.00000000000037184*r^7
> -0.00000000000043768*r^8 + 0.00000000000000172*r^9
r = 5, and the answer 1.83303 is generated . BUT I
> need to start with the answer and solve for r.
In Mathematica...
answer = Solve[
> -0.13249751088801668 + 0.06632187456026009*r^1
> +0.06629492661634432*r^2 - 0.00005387198125569*r^3
> -0.00002692675947693*r^4 + 0.00000001324872853*r^5
> +0.00000000435988550*r^6 - 0.00000000000037184*r^7
> -0.00000000000043768*r^8 + 0.00000000000000172*r^9 ==
> 1.83303, r]
...solves to...
{r -> -61.9036 - 40.911 I}, {r -> -61.9036 + 40.911
> I}, {r -> -59.8256}, {r-> -6.}, {r -> 5}, {r - 73.5579}, {r -> 82.3158 - 32.3924 I}, {r -> 82.3158 +
> 32.3924 I},
> {r -> 200.908}}
and knowing from the origional real world data that r
> is in a range between 0 and 16 .... the solution is
> {r -> 5}.
> _________________________________________________________________
Mathmatically how does the Solve function do this?
> My application needs to dynamically Solve the
> equation, so I need to write something in C.
Any leads greatly appreciated.
> Rick T.
>
What happens is (roughly) this. You are applying Solve, which is an
exact algebraic solve to a polynomial with numerical (approximate)
coefficients. Mathematica first rationalizes the coefficients, then
uses exact methods to solve the exact equation, and finally applies N
to return numerical solutions. To obtain exact solutions mathematica
uses a whole range of algebraic techniques, including factoring of
polynomials and root isolation. Unless you are an expert on
polynomial algebra there is virtually no chance that you could
implement this in C. Oo the other hand, if you were an expert you
wouldl not be asking this ...
The alternative approach is to use NSolve instead of Solve. Solving
numerically univariate polynomial equations is relatively simple, it
reduces to computing eigenvalue of so called Frobenius matrices. This
probably could be implemented in a few pages of C code, once you have
implemented an a program for determining eigenvalues of matrices. You
can find the information on the required numerical polynomial algebra
chapters 2 and 5.
Andrzej Kozlowski
====
Subject: converting notebook to executable?
Is there a method to convert a mathematica notebook or package (.m) file
Tanim Islam
--
Laboratorie de Radioastronomie
Ecole Normale Superieure
75005 Paris CEDEX 05
France
====
Subject: Plot3D slice
I have s 3dplot, and I want to take slice at fixed value along the Z
axis. How to do that? I tried using ContourPlot, but the result doesnt
satisfy me. I spend like two days searching for answer in
P.S. Sorry if I'm asking too common question
====
Subject: Re: saving the kernel
>is there a way to import/export or save the kernel so that I can
>continue working on something on different computers with the same
>results? (in order to save time, and not recalculate all of the
>values)
It greatly depends on how different different is. Take a look at the
documentation for DumpSave. If you are not trying to move from say a Mac to
say a Windows machine, this will probably do what you want.
--
To reply via email subtract one hundred and four
====
Subject: Re: Portable Notebooks and Filenames[]
If you use 'ToFileName' then forward or back slashes shouldn't be required
For eample:
path= ToFileName[{c:,Install,celestia}]
FileNames[*.zip, path]
:= c:Installcelestia
:= {c:InstallcelestiaCelestiaUsersGuide-1.3.2-pdf.zip}
or
path=ToFileName[{c:,Install,celestia},*.zip]
FileNames[path]
:= c:Installcelestia*.zip
:= {c:InstallcelestiaCelestiaUsersGuide-1.3.2-pdf.zip}
Stefan Linnik
~~~~~~~~
in our group we are using Mathematica both on Windows and on Linux (and
> I'm about to convert a MacAddict to Mathematica). However, we are
> facing one problem with external file names.
It is possible to use
In[1]:=
> SetDirectory[some/directory/subdirectory];
(from a syntax point of view; of course the beginning of the string will
> be different, like ~/netdrive vs. w:)
On the other hand, this works only on Linux:
In[2]:=FileNames[subdir/*]
while on Windows, only this construct works:
In[3]:=FileNames[subdir*]
( needs to be escaped because * or nearly any combination
> has some meaning).
This is weird - first because Windows understands the forward slash as a
> directory separator, and second because it means we have to do
> search-replace orgies when trying a notebook on a different OS. This
> would not only happen in a preamble part, but we even have some
> functions that read all data in a subdirectory, for a list of
> subdirectories.
Is there a way to write such expressions portable? Is there, for
> example, an internal variable directory separator that could be used
> in this string? Alternatively, if it's possible to replace by /
(and
> vice versa) by some string matching mechanism, we could write a function
> that does this if some boolean is set once in the notebook, or even
> depending on some internal variable that indicates the OS?
--
> Frank K.9fster
> Inst. f. Biochemie der Univ. Z.9frich
> Debian Developer
>
====
Subject: Re: Portable Notebooks and Filenames[]
a) at least Mathematica under Windows understand
c:/YourFiles
b) ToFileName[] will construct the file name from
the directory names
and the file without the explicit usage of /
or
Jens
frank schrieb im
in our group we are using Mathematica both on
> Windows and on Linux (and
> I'm about to convert a MacAddict to
> Mathematica). However, we are
> facing one problem with external file names.
It is possible to use
In[1]:=
> SetDirectory[some/directory/subdirectory];
(from a syntax point of view; of course the
> beginning of the string will
> be different, like ~/netdrive vs. w:)
On the other hand, this works only on Linux:
In[2]:=FileNames[subdir/*]
while on Windows, only this construct works:
In[3]:=FileNames[subdir*]
( needs to be escaped because * or nearly any
> combination
> has some meaning).
This is weird - first because Windows
> understands the forward slash as a
> directory separator, and second because it means
> we have to do
> search-replace orgies when trying a notebook on
> a different OS. This
> would not only happen in a preamble part, but we
> even have some
> functions that read all data in a subdirectory,
> for a list of
> subdirectories.
Is there a way to write such expressions
> portable? Is there, for
> example, an internal variable directory
> separator that could be used
> in this string? Alternatively, if it's possible
> to replace by / (and
> vice versa) by some string matching mechanism,
> we could write a function
> that does this if some boolean is set once in
> the notebook, or even
> depending on some internal variable that
> indicates the OS?
--
> Frank K.9fster
> Inst. f. Biochemie der Univ. Z.9frich
> Debian Developer
>
====
Subject: Re: expanding a list
Bill Rowe I'd like to construct a list as follows. Say I have a list of reals
>{x1,x2,x3,...xn}, and another list of integers {r,s}. I'd like to
>make a new list
>{{x1,x1,x1,...},{x2,x2,x2....},{x3,x3,x3,...},....,{xn,xn,xn,...}},
>where the first sublist is of length r, and the remaining sublists
>are of length s.
> Assume lst is set to your list of reals, then
> Join[{Table[First@lst,{r}]},Rest@Transpose@Table[lst, {s}]]
> should give you what you want.
Most elegant! MJ
====
Subject: Re: expanding a list
Hi Mark,
I think the following lines do the trick (first we create some data,
then we define a function called listExpand):
In[1]:=
data = {1.02, 5.7, 3.987, 4.212, 9.11}
Out[1]=
{1.02,5.7,3.987,4.212,9.11}
In[2]:=
listExpand[L_, r_, s_] := FlattenAt[{Table[L[[1]], {r}],
(Table[#1, {s}] & ) /@ Rest[L]}, 2];
In[3]:=
listExpand[data, 3, 5]
Out[3]=
{{1.02,1.02,1.02},{5.7,5.7,5.7,5.7,5.7},{3.987,3.987,
3.987,3.987,3.987},{4.212,4.212,4.212,4.212,4.212},{
9.11,9.11,9.11,9.11,9.11}}
====
Subject: Re: expanding a list
I'd like to construct a list as follows. Say I have a list of reals
> {x1,x2,x3,...xn}, and another list of integers {r,s}. I'd like to
> make a new list
{{x1,x1,x1,...},{x2,x2,x2....},{x3,x3,x3,...},....,{xn,xn,xn,...}},
> where the first sublist is of length r, and the remaining sublists
> are of length s.
Hi Mark,
I think the following lines do the trick (first we create some data,
then we define a function called listExpand):
In[1]:=
data = {1.02, 5.7, 3.987, 4.212, 9.11}
Out[1]=
{1.02,5.7,3.987,4.212,9.11}
In[2]:=
listExpand[L_, r_, s_] := FlattenAt[{Table[L[[1]], {r}],
(Table[#1, {s}] & ) /@ Rest[L]}, 2];
In[3]:=
listExpand[data, 3, 5]
Out[3]=
{{1.02,1.02,1.02},{5.7,5.7,5.7,5.7,5.7},{3.987,3.987,
3.987,3.987,3.987},{4.212,4.212,4.212,4.212,4.212},{
9.11,9.11,9.11,9.11,9.11}}
/J.M.
====
Subject: Help with the User Interface in Mathematica 5.1.1
Hi! I'm new to Mathematica, and I'm currently working with v5.1.1.
I've been searching through messages, documentation, etc... but I can't find
any workable solutions to what should be simple questions about the UI. And
right now, I only have two:
1. How can I set the default size for the Notebook windows?
I've tried to set Preferences / Notebook Options / Window Properties /
Window Size. The documentation says that this is what these variables are
for. But changing them doesn't seem to have any visible effect. New
Notebook windows still get created at the exact same size.
2. How can I get Mathematica to start up maximized?
It starts up *almost* maximized, but I'd like it to actually *be*
maximized. Is there any way to do this?
====
Subject: Re: Applying function to nested lists
I'm trying to get Mathematica to do the following:
Suppose
> x = {{1,2,3},{{4,5,6},7,8},9}
> f = some function
How can I get f applied to each element of x but with the list structure
> intact? I.e. I want something that generates:
{{f[1],f[2],f[3]},{{f[4],f[5],f[6]},f[7],f[8]},f[9]}
-Kerry Kim
>
The problem here is that not all your numbers are at the same level with
respect to the lists (otherwise, you could just use Map with a suitable
levelspec), so one solution is to let f apply everywhere and then prune
out the cases where f is applied to a list:
Map[f,x,[Infinity]]//. f[x_List]->x
If f is actually a function that does something, use a function g that
has no definition, and then replace g with f.
This will work fine providing the data in your nested lists is simple
numbers or variables, but if you might have algebraic expressions in
there, then you would need a more complicated approach to avoid
inserting f inside the expressions.
David Bailey
http://www.dbaileyconsultancy.co.uk
====
Subject: Re: Applying function to nested lists
You need a levelspec in Map:
Map[f, x, {-1}]
-1 to specify the last element
{} to specify only last element
Stefan Linnik
~~~~~~~~
I'm trying to get Mathematica to do the following:
Suppose
> x = {{1,2,3},{{4,5,6},7,8},9}
> f = some function
How can I get f applied to each element of x but with the list structure
> intact? I.e. I want something that generates:
{{f[1],f[2],f[3]},{{f[4],f[5],f[6]},f[7],f[8]},f[9]}
-Kerry Kim
>
====
Subject: Re: Applying function to nested lists
I'm trying to get Mathematica to do the following:
Suppose
>x = {{1,2,3},{{4,5,6},7,8},9}
>f = some function
How can I get f applied to each element of x but with the list structure
>intact? I.e. I want something that generates:
{{f[1],f[2],f[3]},{{f[4],f[5],f[6]},f[7],f[8]},f[9]}
-Kerry Kim
>
Try this,
Cos[#] & /@ x
(# + 1) & /@ x
or you can try
Cos[y] /. {y -> x}
Sqrt[y] /. {y -> x}
Hope this is what you are looking for
Pratik
--
Pratik Desai
Graduate Student
UMBC
Department of Mechanical Engineering
Phone: 410 455 8134
====
Subject: Re: Applying function to nested lists
I'm trying to get Mathematica to do the following:
Suppose
> x = {{1,2,3},{{4,5,6},7,8},9}
> f = some function
How can I get f applied to each element of x but with the list structure
> intact? I.e. I want something that generates:
{{f[1],f[2],f[3]},{{f[4],f[5],f[6]},f[7],f[8]},f[9]}
-Kerry Kim
>
Use Map with a level specification:
In[3]:=
Map[f, x, {-1}]
Out[3]=
{{f[1], f[2], f[3]}, {{f[4], f[5], f[6]}, f[7], f[8]}, f[9]}
Carl Woll
Wolfram Research
====
Subject: Re: Applying function to nested lists
I'm trying to get Mathematica to do the following:
Suppose
> x = {{1,2,3},{{4,5,6},7,8},9}
> f = some function
How can I get f applied to each element of x but with the list structure
> intact? I.e. I want something that generates:
{{f[1],f[2],f[3]},{{f[4],f[5],f[6]},f[7],f[8]},f[9]}
-Kerry Kim
>
Map[f, x, {-1}] is what you're looking for.
--
Peter Pein
Berlin
====
Subject: Re: Applying function to nested lists
Map[f, x, {-1}]
Jens
Kerry Kim schrieb im
I'm trying to get Mathematica to do the
> following:
Suppose
> x = {{1,2,3},{{4,5,6},7,8},9}
> f = some function
How can I get f applied to each element of x but
> with the list structure
> intact? I.e. I want something that generates:
{{f[1],f[2],f[3]},{{f[4],f[5],f[6]},f[7],f[8]},f[9]}
-Kerry Kim
>
====
Subject: Re: Applying function to nested lists
I'm trying to get Mathematica to do the following:
Suppose
> x = {{1,2,3},{{4,5,6},7,8},9}
> f = some function
How can I get f applied to each element of x but with the list structure
> intact? I.e. I want something that generates:
{{f[1],f[2],f[3]},{{f[4],f[5],f[6]},f[7],f[8]},f[9]}
-Kerry Kim
One way is just to tell Mathematica to Map your function across any List
it comes across. In the example below I've left f undefined for any
inputs except lists, but you could easily define it for other inputs
with an f[n_Integer]:= type of statement, for integers, for
example.
In[1]:=
x = {{1, 2, 3}, {{4, 5, 6}, 7, 8}, 9};
In[2]:=
f[n_List] := f /@ n
In[3]:=
f[x]
Out[3]=
{{f[1], f[2], f[3]}, {{f[4], f[5], f[6]}, f[7], f[8]}, f[9]}
You can accomplish the same thing by changing the attribute of your
function to Listable, a course which I'm sure other posts will provide
more details on.
--
Curt Fischer
====
Subject: Re: Mouse controlled 3D rotations
Surprisingly Mathematica does not support mouse controlled rotations. The
> graphics are composed in a manner that makes this possible but it is not
> implemented.
My normal approach is to use the free applet from Martin Kraus which
works
> very well. It may be found at
http://www.vis.uni-stuttgart.de/~kraus/LiveGraphics3D/
However, Mathematica does now have a GUIkit and this should be the
internal
> way of making mouse controlled rotations. I have had a go at making the
> GUIkit undertake this task. It works but it is not very successful
because
> it is so slow. I enclose my development example, below, in case anyone
can
> see a way to make this work quickly.
For your animations issues you should be aware that the normal route is
to
> make a number of slides and then double click on one slide to get the
> animations to work. If you search the mathgroup archive you will find
code
> for collapsing all the slides after they have been produced to give a
neater
> effect.
Hugh Goyder
Needs[GUIKit`]
> gg = Graphics3D[
> Plot3D[Sin[x y], {x, 0, Pi}, {y, 0, 2Pi}, PlotPoints -> {30, 30},
> ColorFunction -> Hue]];
> ex = Widget[Panel, {
> {Widget[Label, {text -> x:}],
> Widget[Slider,
> {BindEvent[change, Script[sliderFunc[];]]},
> Name -> sx,
> WidgetLayout -> {Stretching -> {Maximize, False}}]},
{Widget[Label, {text -> y:}],
> Widget[Slider,
> {BindEvent[change, Script[sliderFunc[];]]},
> Name -> sy,
> WidgetLayout -> {Stretching -> {Maximize, False}}]},
{Widget[Label, {text -> z:}],
> Widget[Slider,
> {BindEvent[change, Script[sliderFunc[];]]},
> Name -> sz,
> WidgetLayout -> {Stretching -> {Maximize, False}}]},
Widget[MathPanel,
> {preferredSize - Widget[Dimension, {width -> 288, height -> 288}]},
> Name -> canvas,
> WidgetLayout -> {Stretching -> {True, Maximize}}],
> preferredSize - Widget[Dimension, {width -> 288, height -> 340}],
BindEvent[componentResized, Script[sliderFunc[];]],
Script[
> sliderFunc[] := Module[{ax, ay, az },
> ax = ToExpression[PropertyValue[{sx, value}]];
> ay = ToExpression[PropertyValue[{sy, value}]];
> az = ToExpression[PropertyValue[{sz, value}]];
> expr = Show[gg, PlotRange -> All, ViewPoint -> {ax, ay, az},
> DisplayFunction -> Identity];
SetPropertyValue[{canvas, mathCommand},
> ToString[expr, InputForm]] ];
> sliderFunc[];
> ]
}];
> RealTimePlot[] := GUIRun[ex, IncludedScriptContexts -> {$Context}];
RealTimePlot[]
>>Is there a way to build a 3D graphics object (e.g., a simple
>>Tetrahedron) and manipulate it (e.g., rotate it in 3D) with the mouse?
>>There is an example on webMathematica of just this, but I haven't
>>figured out how to do it at all in plain ol' Mathematica.
>>Does it matter what system I'm on (AIX 5.1 or WinXP)?
>>I noticed that on AIX5.1, starting math kernel (no notebooks) that I can
>>use Animate[] to make a movie of a rotating Tetrahedron. In XP, the
>>same doesn't produce anything. On either system, in a notebook, I just
>>get multiple graphics objects, one for each rotational position --
>>there's no live animation.
>>Any guidance is appreciated.
>>Jim Hafner
>>hafner@almaden.ibm.com
>>
>
I have been working on my Super Widget Package designed to simplify
and extend the use of GUIKit. In the version that I will release soon,
there is a LiveGraphics3D super widget. This uses Martin Kraus'
LiveGraphics3D applet, but embeds it in a larger GUIKit GUI. Please
contact me for more details, or look on my website.
David Bailey
http://www.dbaileyconsultancy.co.uk
====
Subject: Re: Mouse controlled 3D rotations
O.K. since nobody has tried to answer I shall have a go. But first I
want to state that I have no connection with WRI and no access to any
inside knowledge and in particular I am not breaking any non-
disclosure agreements because I have never signed any. I have only
seen some public demos.
Now, on the basis of that I would say is that the reason is that the
OpenGL based RealTime3D was always intended only as a stop-gap
measure before Wolfram's new graphics system, which will allow you to
do everything that RealTime3D does and much more, is ready. It
probably has taken longer to get that system to work than was
originally expected, but since it was always intended to completely
replace RealTime3D no attempt was made to seriously improve the
latter or to integrate it with the rest of Mathematica. I suspect the
present version is the last one in which the OpenGL based RealTime3D
is going to be found. The fact that no attempt was ever made to
integrate it with the Mathematica kernel means that there is no need
to worry about backward compatibility.
All the above is pure speculation of course and carries no authority
whatever.
Andrzej Kozlowski
Use experimental package < Then, when plotting 3D object with Show you can rotate 3d with mouse.
The formatting of the plot is completely destroyed though.
I do not figure out why. I asked also to the list but I did not
> receive any
> reply.
Bye,
Marco
>> Is there a way to build a 3D graphics object (e.g., a simple
>> Tetrahedron) and manipulate it (e.g., rotate it in 3D) with the
>> mouse?
>> There is an example on webMathematica of just this, but I haven't
>> figured out how to do it at all in plain ol' Mathematica.
>> Does it matter what system I'm on (AIX 5.1 or WinXP)?
>> I noticed that on AIX5.1, starting math kernel (no notebooks) that
>> I can
>> use Animate[] to make a movie of a rotating Tetrahedron. In XP, the
>> same doesn't produce anything. On either system, in a notebook, I
>> just
>> get multiple graphics objects, one for each rotational position --
>> there's no live animation.
>> Any guidance is appreciated.
>> Jim Hafner
>> hafner@almaden.ibm.com
>
====
Subject: Re: Applying function to nested lists
x={{1,2,3},{{4,5,6},7,8},9};
x/.a_?NumericQ:>f[a]
{{f(1),f(2),f(3)},{{f(4),f(5),f(6)},f(7),f(8)},f(9)}
or if f is or can be made Listable
SetAttributes[f, Listable];
f[x]
{{f(1),f(2),f(3)},{{f(4),f(5),f(6)},f(7),f(8)},f(9)}
%==%%%
True
Bob Hanlon
>
====
> Subject: Applying function to nested lists
> I'm trying to get Mathematica to do the following:
Suppose
> x = {{1,2,3},{{4,5,6},7,8},9}
> f = some function
How can I get f applied to each element of x but with the list structure
> intact? I.e. I want something that generates:
{{f[1],f[2],f[3]},{{f[4],f[5],f[6]},f[7],f[8]},f[9]}
-Kerry Kim
====
Subject: Re: saving the kernel
Use DumpSave[] to store your notebook.
When you are on the new computer load the file generated byDumpSave[] with
Get[]
i.e.,
(*Old Computer *)
a=1;b=2;c=Range[10];
DumpSave[c:myDump.mx];
Now close Mathematica, copy or move the file c:MyDump.mx to the new
computer
(*new computer *)
< working on something on different computers with the same results? (in
order
> to save time, and not recalculate all of the values)
> Guy
>
====
Subject: Re: saving the kernel
Hi Guy,
Have a look at the command _DumpSave_. Beware that since the saved file
is some binary format, it might not be readable on a different computer
architecture.
====
Subject: Re: saving the kernel
you can try DumpSave[] but it work only on the
same type of computers.
Jens
Guy Israeli schrieb im
is there a way to import/export or save the
> kernel so that I can continue
> working on something on different computers with
> the same results? (in order
> to save time, and not recalculate all of the
> values)
> Guy
====
Subject: Re: saving the kernel
is there a way to import/export or save the kernel so that I can continue
> working on something on different computers with the same results? (in
order
> to save time, and not recalculate all of the values)
I asked this question a few months ago and thus discovered the DumpSave
and DumpGet commands. Unfortunately I've not discovered a way of
getting mathematica to save a notebook preserving the In[] and Out[]
tags so that I can reload a notebook, load a copy of the kernel space
and continue from where I left off - the In[] and Out[] statements are
missing from the reloaded notebook. I would welcome a solution to that
problem.
,678
====
Subject: For Loop and Array related
Hi All,
I have an array with 100 elements, all set to zero initially. Then I
want to randomly choose one element and increase its value by one, and
repeat this 16000 times. Here is my code:
Lattice = Table[0, {n, 100}];
For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++]
So now if I add all the elements in the list Lattice together, I should
get 16000 (I use Total[Lattice] to get the sum of the list). But this
doesn't happen, and strangely, each time I run this, the sum of the
list is different! What am I doing wrong?
Also I'm aware that a lot of Mathematica newbies try and write code
like it were C++ and I think i've fallen into this trap as well. So is
there a different (more Mathematica) way which I can implement the
above?
====
Subject: Re: Help with the User Interface in Mathematica 5.1.1
Create the file given by:
ToFileName[{$UserAddOnsDirectory, Autoload, My, FrontEnd},
init.m]
Put the following command:
SetOptions[InputNotebook[],
WindowMargins->{{0,0},{0,0}},
WindowSize->{Automatic,Automatic}
]
This will resize the startup nb to fill the screen.
----------------------------------------------
Omega Consulting
The final answer to your Mathematica needs.
http://omegaconsultinggroup.com
Hi! I'm new to Mathematica, and I'm currently working with
> v5.1.1.
> I've been searching through messages, documentation, etc... but I
> can't find
> any workable solutions to what should be simple questions about the
> UI. And
> right now, I only have two:
> 1. How can I set the default size for the Notebook windows?
I've tried to set Preferences / Notebook Options / Window
> Properties /
> Window Size. The documentation says that this is what these
> variables are
> for. But changing them doesn't seem to have any visible effect. New
> Notebook windows still get created at the exact same size.
2. How can I get Mathematica to start up maximized?
It starts up *almost* maximized, but I'd like it to actually *be*
> maximized. Is there any way to do this?
>
====
Subject: Re: spotlight escape sequences
> os x only:
how do you type:
Needs[Combinatorica`]
into apple's os x spotlight and get back what you expect?
Surrounding the whole thing in quotes (with no escaping on the inner
quotes) seems to work for me:
Needs[Combinatorica`]
Have you installed the Wolfram Notebook Indexer plugin for Spotlight
? This is an
example of a search that will not work without it.
-Rob (author of Wolfram Notebook Indexer plugin for Spotlight)
====
Subject: Plot difficulties
I have a question regarding Plot. Here is a snip of my code:
Plot[function1, {EE,0 ,2.9*1.6 10^-19}, PlotLabel->function1];
Plot:: plnr : function1 is not a machine-sized real number at EE =
6.652531793826348`*^-21
...
function1 evalutates to 0. + 0.00195313i at this point. In fact, at every
point the plot command gives an error the evaluation is completly
imaginary.
Function1 is composed as follows:
Sqrt[1/(k1 Rc)] Sqrt[1/(k2i Rs)] (k2i m1 Rc Cos[k2i (Rc - Rs)] Sin[k1 Rc] -
(k1 m2 Rc Cos[k1 Rc] + (m1 - m2) Sin[k1 Rc]) Sin[k2i (Rc - Rs)])/ (m1
(Sqrt[1/(k2i Rc)] * Sqrt[k1 Rc] Sqrt[k2i Rc] Sqrt[k2i Rs])
Where k2i is completely imaginary, m1>m2, and Rs>Rc
Any Suggestions?
Eric
====
Subject: Re: Plot3D slice
same with ContourPlot and PlotRange :)
> You are probably looking for ImplicitPlot
====
Subject: List operations
suppose i have a list containing a whole book, the list will contain
words, sentences, chapters; as an example:
lst={{{abc,def},{as,red}},{{fat,qqq,qqq},
{asd,asd,vbn}},{{zz,zz}},{{zz,wtt,wtt}},{{
red,zz},
{sd,ed},{er,to}},{{ww,ww,dff},{as,end}}}
please check sometimes some servers may insert the false - letter
in the above lst.
here is the book lst contains six chapters, 11 sentences,
the question is: what are the general methods wich could be used to
know how many words, and how many sentences and how many chapters
between an arbitrary two words in the book such as an example:
between the word number 2 in sentence 2 in chapter 2
and the word number 2 in sentence 1 in chapter 5
ie:
wrd1=lst[[2]][[2]][[2]]
wrd2=lst[[5]][[1]][[2]]
the results will be: if we count the 2 words and their own sentences
and chapters:
9 words, 4 sentences, 4 chapters.
reards.
Anton
====
Subject: Randomness Test
Okay, I have a sequence of numbers as below. When i do a scatter plot, there
seems to be a bias toward positive numbers. Although when I run some tests
like runs test, it shows me that the numbers are random. If that is the
case, then when i plot the numbers on a scatter plot, should'nt they be
equally divided up and below the x axis? My goal is to prove that that there
is a significant bias towards positive numbers.
-0.164971751
1.137014315
0.622389791
0.048958333
1.232944503
0.3241877
0.1015
0.075538717
0.265537849
-0.175252257
0.279807692
-0.409979424
0.628232355
-0.137667494
0.210711568
-0.984059857
-0.016778523
0.384063745
0.079707844
-0.183936235
-0.567394095
0
0.277777778
0.785185185
0.267555556
0.078717201
0.344352617
0
0.442245021
0.310665658
0.788764045
0.015850552
-0.054098361
0
0
0.929482371
0.278787879
0.123773346
0.125175809
0
0
====
Subject: fitting multiple datasets
I have two questions,
1) I have multiple datasets, and one function that depend on multiple
parameters, of which I would like to find a global best fit to three of the
parameters. However, within each dataset, I need to specify slightly
different parameters within the function. For example (not actual function
and will not make sense),
f(a_,b_,c_,d_,e_) = a*x^5 + b*x^4 + c*x^3 + d*x^2 + e*x
In datasets 1-5, I would like to specify different a and b values
(for
each dataset), while finding the best single fit (global) for c, d,
and
e in the function using all datasets.
I see that using FindFit one can enter multiple points of the same
dataset, and minimize the parameters of a function to best fit one dataset,
but is it possible to enter multiple datasets and find a global minimum for
multiple parameters in a function? Or do I need to write my own loop in
Mathematica?
2) When I am doing a minimization using FindFit how do I tell the
minimization routine that I am only interested in solutions (assuming they
exist as local minima) that satisfy a certain range. For example, a
solution to a parameter that is only within the range {a,b}.
Nate
====
Subject: Re: make a set of conditions without the parameters
I have a big list made out of smaller lists. I want to filter out
specific
> smaller lists, for instance those who have 1 in the first place and 3 in
the
> 7th place.
I know what item cannot be in what place for the condition described
above
> but the only thing i could do is to do those rules using string like
this:
> t2 = {{0, 0, 0, {3}, 0, {4}, 0, 0, 0}, {0, {7}, {3}, 0, 0, 0, {1}, {4},
0},
> {{4},
> 0, 0, 0, {7}, 0, 0, 0, {6}}, {0, {9}, {5}, {4}, 0, {6}, 0, 0, 0}, {{8},
0,
> 0, 0, {9}, 0, 0, 0, {3}}, {0, {4}, {6}, {8}, 0, {1}, 0, 0, 0}, {{6}, 0,
> 0, 0, 0, 0, 0, 0, {5}}, {0, {2}, {7}, 0, 0, 0, {3}, {8}, 0}, {0, 0,
> 0, {5}, 0, {7}, 0, 0, 0}};
> rulesperline = Table[MapIndexed[ToString[#[[] <> ToString[#1] < ToString[]]!=] <> ToString[#2] &, (Part[#, i] & /@
Partition[Flatten[t2],
> 9] ) // Flatten], {i, 1, 9}];
newrules = Fold[(#1 /. ToString[#[[0]]!={] <> ToString[#2] < ToString[}] -> X) &,
> rulesperline, Range[9]]
which will result in
{{X, X, #[[4]]!={3}, X, #[[8]]!={5}, X, #[[6]]!={7}, X, X}, {X,
#[[7]]!={2},
> X, #[[9]]!={4}, X, #[[4]]!={6}, X, #[[2]]!={8}, X}, {X, #[[3]]!={2},
> X, #[[5]]!={4}, X, #[[6]]!={6}, X, #[[7]]!={8}, X}, {#[[3]]!={1}, X,
> X, #[[4]]!={4}, X, #[[8]]!={6}, X, X, #[[5]]!={9}}, {X, X, #[[7]]!={3},
> X, #[[9]]!={5}, X, X, X, X}, {#[[4]]!={1}, X, X, #[[6]]!={4},
> X, #[[1]]!={6}, X, X, #[[7]]!={9}}, {X, #[[1]]!={2}, X, X, X, X,
> X, #[[3]]!={8}, X}, {X, #[[4]]!={2}, X, X, X, X, X, #[[8]]!={8}, X}, {X,
> X, #[[6]]!={3}, X, #[[3]]!={5}, X, #[[5]]!={7}, X, X}}
and then to cancel the underlines
newrulesfull = Select[#, # != X &] & /@ newrules
{{#[[4]]!={3}, #[[8]]!={5}, #[[6]]!={7}}, {#[[7]]!={2}, #[[9]]!={4},
> #[[4]]!={6}, #[[2]]!={8}}, {#[[3]]!={2}, #[[5]]!={4}, #[[6]]!={6},
> #[[7]]!={8}}, {#[[3]]!={1}, #[[4]]!={4}, #[[8]]!={6}, #[[5]]!={9}},
> {#[[7]]!={3}, #[[9]]!={5}}, {#[[4]]!={1}, #[[6]]!={4}, #[[1]]!={6},
> #[[7]]!={9}}, {#[[1]]!={2}, #[[3]]!={8}}, {#[[4]]!={2}, #[[8]]!={8}},
> {#[[6]]!={3}, #[[3]]!={5}, #[[5]]!={7}}}
The X here is just to mark that it is unimportnat.
however, each element is a string here. and now starts my problem
I would want to do Select[somelist, And[newrulesfull [[1]]]&] meaning it
> will give the elements in somelist that match the all of the conditions
in
> rulesperline[[1]]. But since it is a string it doesn't do much, and
> everytime I do ToExpression it gives me a lot of errors because it
doesn't
> know what #[[4]] or some other number is.
How can I make a list of rules like that so that I can use Select on
those
> conditions?
Short answer: use x[[{positions}]] != {values} as your test.
In[1]:= t2 = {{ 0, 0, 0, {3},0,{4},0, 0, 0 },
{ 0,{7},{3}, 0, 0, 0,{1},{4},0 },
{{4},0, 0, 0,{7},0, 0, 0,{6}},
{ 0,{9},{5},{4},0,{6},0, 0, 0 },
{{8},0, 0, 0,{9},0, 0, 0,{3}},
{ 0,{4},{6},{8},0,{1},0, 0, 0 },
{{6},0, 0, 0, 0, 0, 0, 0,{5}},
{ 0,{2},{7}, 0, 0, 0,{3},{8},0 },
{ 0, 0, 0, {5},0,{7},0, 0, 0 }};
In[2]:= {u2,v2} = Transpose[Transpose@Select[
Transpose@{Range@Length@#,#},ListQ[#[[2]]]&]&/@t2]
Out[2]= {{{4,6}, {2,3,7,8}, {1,5,9}, {2,3,4,6}, {1,5,9}, {2,3,4,6},
{1,9}, {2,3,7,8}, {4,6}},
{{{3},{4}}, {{7},{3},{1},{4}}, {{4},{7},{6}},
{{9},{5},{4},{6}}, {{8},{9},{3}}, {{4},{6},{8},{1}},
{{6},{5}}, {{2},{7},{3},{8}}, {{5},{7}}}}
u2[[i]] gives the important positions in row i of t2.
v2[[i]] gives the corresponding values.
If the important elements in t2 were given as {x}
only to mark them as important and to allow for {0},
and if the values in the to-be-inspected lists
will all be simple scalars, then Flatten the rows of v2:
In[3]:= v2 = Flatten/@v2
Out[3]= {{3,4}, {7,3,1,4}, {4,7,6}, {9,5,4,6}, {8,9,3}, {4,6,8,1},
{6,5}, {2,7,3,8}, {5,7}}
In[4]:= x = Table[Random[Integer,9],{10^4},{9}];
In[5]:= Table[Length@Select[x,#[[u2[[i]]]] != v2[[i]]&],{i,Length@t2}]
Out[5]= {9896, 10000, 9991, 9998, 9988, 9997, 9912, 9999, 9889}
Here are the 9 lists that were rejected by rule 3:
In[6]:= With[{i = 3}, Select[x, #[[u2[[i]]]] == v2[[i]]&]]
Out[6]= {{4,5,6,8,7,8,4,5,6},
{4,8,9,8,7,6,2,4,6},
{4,7,8,6,7,9,5,8,6},
{4,1,2,7,7,6,0,3,6},
{4,0,1,3,7,3,3,3,6},
{4,2,4,5,7,7,4,9,6},
{4,2,8,0,7,8,3,5,6},
{4,1,3,6,7,8,4,0,6},
{4,2,3,6,7,0,9,2,6}}
====
Subject: Re: Write/WriteString -- writing delimited txt to a stream?
A simple way might be something like:
(* init file.txt *)
strm= OpenAppend[c:file.txt]
Do[
...
dataChunk= { {100, 1.5, -10}, {200, 3.2, 10}, ...etc};
Export[strm, dataChunk, CSV]
...
]
Stefan Linnik
~~~~~~~~
Situation:
> - I am reading data in from a stream (the file is too big to import)
> and processing it chunk by chunk.
> - The proesssed data looks something like data = {{100, 1.5, -10},
> {200,3.2, 10},...etc}
> - I have opened an output stream to write the data using s =
> OpenWrite[file, FormatType -> OutPutForm];
> - I want to write the data in tab or comma separated format with one row
> per line.
Problem:
> - No matter what I've tried, I always get either
> (i) output with rows enclosed in brackets, or
> (ii) delimited text output, but with Mathematica automatically adding a
> line
> break if a line exceeds what seems to be the default width for output
> format
> - I've tried using Write and WriteString -- nothing seems to work.
> - I also tried generating an exact string for each line using a function
> that inserts tabs between list items and adds a newline at the end of
> the list.
ExpressionToTSV[list_] := Module[{temp},
> temp = ToString@Rest@(ToString /@ Flatten@({t, #} & /@
list));
> StringReplace[temp, {{ -> , } -> , , ->
}];
> StringInsert[temp, n, -1]
> ];
> There must be a simple solution -- does anyone know how to do this?
Any help would be greatly appreciated,
> Lee
>
====
Subject: Re: spotlight escape sequences
>os x only:
>how do you type:
>Needs[Combinatorica`]
>into apple's os x spotlight and get back what you expect?
I think the answer is you can't do this as things are currently set up.
However, since I also use Mac OS 10.4, I would be glad to learn I am wrong.
The problem is Spotlight doesn't index file content. The few exceptions to
this (e.g. PDF files) seem to be only those file types Apple uses
extensively. I suppose Wolfram could put this functionality into the notebook
mdimporter they created. But at the moment, this importer does not appear to
do much at all with notebook content.
--
To reply via email subtract one hundred and four
====
Subject: How to rotate a PolarPlot?
Hi All,
Would appreciate some help with this. I would like to know how I can
rotate the following plot to an arbitrary angle:
PolarPlot[Exp[.2t], {t, 0, 8p}, PlotStyle -> Red,
PlotRange -> All, AspectRatio -> Automatic, Ticks -> None]
Paul
====
Subject: Re: Re: Peculiar behaviour of Mathematica code
> It is strange that NextLexicographicSubset and NextGrayCodeSubset both
> break down on certain subsets and NextGrayCodeSubset is useless for
> incrementally generating the power set:
In[1]:= < {m, n,
> s}) expected at position 3 in Drop[{c}, -2, a].
Out[2]= Drop[{c}, -2, a]
In[3]:= NextGrayCodeSubset[{a, b, c}, {c}]
Part::partw: Part 4 of {a, b, c} does not exist.
Part::partw: Part 4 of {a, b, c} does not exist.
Out[3]= {c, {a, b, c}[[4]]}
Maxim Rytin
> m.r@inbox.ru
The code for NextLexicographicSubset in the Combinatorica package is:
NextLexicographicSubset[l_List,s_List]:=Module[{elem},If[Last[
Append[
Drop[s,-2],l[[Position[l,elem][[1,1]]+1]]]),Append[
s,l[[Position[l,Last[s]][[1,1]]+1]]]]]
This is obviously going to break down when the list s consists just
of the element Last[l]. The correct code should be:
NextLexicographicSubset[l_List, s_List] := Module[{elem}, If[
If[Length[s] == 1, {}, Append[Drop[s, -2], l[[
Position[l, elem][[1, 1]] + 1]]]]), Append[s, l[[Position[l,
Last[s]][[
1, 1]] + 1]]]]]
It seems strange that this bug has survived so long!
I assume the other cases are of the same kind although I have not
checked this.
Andrzej Kozlowski
Chiba, Japan
====
Subject: plot3D over a triangular domain
thread-index: AcVxXma5q0SB1ElOSiaoMHbNlA+3Vw==
Hi All,
I would like to plot a function over a isosceles triangular domain.
I mean Plot3D[function, {x,-1,1},{y, -0.5+0.5x, 0.5-0.5x}]. But I got
message that the limit must be real number. Anyone can help me?
Tun Myint Aung
Graduate Student
National University of Singapore
E1A #02-18
E-mail g0202015@nus.edu.sg
====
Subject: problem with InverseLaplaceTransform
I'm pretty new to Mathematica and am having difficulty trying to derive
an inverse laplace transform using Mathematica. When I run the code,
Mathematica starts to run (says running...), but then just continues
to remain like that and doesn't give an answer....as if it has crashed
or something. The code I`m trying to run is below (layout messed up,
but if you copy and paste it back into Mathemtica it`s fine):
InverseLaplaceTransform[{{(muone (mufour + s) (lambdathree + muthree +
s) (lambdatwo + mutwo + s) +
lambdaone (lambdathree (lambdatwo mufour +
mutwo (mufour + s)) + (mufour +
s) (lambdatwo muthree +
mutwo (muthree + s))))/(s (mufour + s)
(lambdaone +
muone + s) (lambdathree + muthree + s) (lambdatwo +
mutwo +
s) (1 - (muone (mufour + s) (lambdathree + muthree +
s) (lambdatwo + mutwo + s) +
lambdaone (lambdathree (lambdatwo mufour +
mutwo (mufour + s)) + (mufour +
s) (lambdatwo muthree +
mutwo (muthree + s))))/((mufour +
s) (lambdaone + muone + s) (lambdathree +
muthree +
s) (lambdatwo + mutwo + s))))}}, s, t]
Can anybody explain my problem?
Barry