mm-847
===
Subject: Applying a list of functions to a single number
Applying a list of functions to a single number
I have
Square[x_]:=x^2
Cube[x_]:=x^3
I have tried
In[2]:={Square,Cube} @ 5
Out[2]:= {Square,Cube}[5]
But what I wanted is a list containing
{25,125}
Obviously I'm doing this the wrong way. What is the correct way?
===
Subject: Re: Applying a list of functions to a single number
In[13]:=
square[x_] := x^2
cube[x_] := x^3
In[15]:=
Through[{square, cube}[5]]
Out[15]=
{25,125}
In[16]:=
({square[#1], cube[#1]} & )[5]
Out[16]=
{25,125}
In[17]:=
(#1[5] & ) /@ {square, cube}
Out[17]=
{25,125}
In[18]:=
{square[5], cube[5]}
Out[18]=
{25,125}
In[19]:=
Out[19]=
{25,125}
In[20]:=
Flatten[({square[#1], cube[#1]} & ) /@ {5}]
Out[20]=
{25, 125}
In[22]:=
Information[Through]
Through[p[f1, f2][x]] gives p[f1[x], f2[x]]. Through[expr, h]
performs the transformation wherever h
occurs in the head of expr.
Attributes[Through] = {Protected}
Dimitris
=CF/=C7 siewsk@bp.com =DD=E3=F1=E1=F8=E5:
===
Subject: Re: Applying a list of functions to a single number
What you need is the function *Through* [1, 2]. For instance,
In[1]:=
square[x_] := x^2
cube[x_] := x^3
Through[{square, cube}[5]]
Out[3]=
{25, 125}
Note that Square (with a capital S) is already defined in Mathematica.
Indeed, every Mathematica function starts with an uppercase letter (this
is a convention established ages ago by Wolfram Research). To avoid any
clash, it is better to use user-defined names starting with a lowercase
letter.
Jean-Marc
[1] http://documents.wolfram.com/mathematica/functions/Through
[2] 2.2.9 Advanced Topic: Working with Operators,
http://documents.wolfram.com/mathematica/book/section-2.2.9
===
Subject: Re: Applying a list of functions to a single number
two of them are:
Cube[x_] = x*(Square[x_] = x^2);
Through[{Square, Cube}[5]]
{25, 125}
#[5]& /@ {Square, Cube}
{25, 125}
===
Subject: Re: Applying a list of functions to a single number
Here are some of the correct ways
{#^2,#^3}&[5]
{Square[#],Cube[#]}&[5]
Raj
===
Subject: CoefficientList
I'm having a little trouble understanding how CoefficientList works
for multivarate polynomials. In the Mathematica book, there is this
example:
t = (1 + x)^3 (1 - y - x)^2
Expand[t]
1 + x - 2x^2 - 2x^3 + x^4 + x^5 - 2y - 4xy + 4x^3y + 2x^4y + y^2 +
3xy^2 + 3x^2y^2 + x^3y^2
CoefficientList[t,{x,y}]
{{1, -2, 1}, {1, -4, 3}, {-2, 0, 3}, {-2, 4, 1}, {1, 2, 0}, {1, 0, 0}}
I am confused as to what each entry of the output of the
CoefficientList corresponds to. The Handbook says:
For multivariate polynomials, CoefficientList gives an array of the
coefficients for each power of each variable.
So what exactly do the entries of the first item, {1,-2,1}, correspond
to? Is it the 0 order terms? Why three entries then? Is
corresponding to the 1, the x, and the -2y? What is the order of each
of these lists? Maybe I'm just being dense, but it isn't immediately
obvious to me how this is structured, and the Handbook is extremely
terse in its description.
Any help would be greatly appreciated.
~Luke
===
Subject: Re: CoefficientList
Hi Luke,
Say we have a multivariate polynomial in x and y with highest powers n
and m, respectively. The function CoefficientList returns a rectangular
array where the rows correspond to the increasing powers of x (0 to n,
from top to bottom) and the column columns correspond to the increasing
powers of y (0 to m, from left to right). Each entry displays the
corresponding coefficient. For instance,
In[1]:=
p = a + b*x^3 + c*x^2*y + d*x*y^2 + e*y^3;
Exponent[p, {x, y}]
CoefficientList[p, {x, y}]
{y^0, y^1, y^2, y^3}}]
Out[2]=
{3, 3}
Out[3]=
{{a, 0, 0, e}, {0, 0, d, 0}, {0, c, 0, 0}, {b, 0, 0, 0}}
Out[4]=
Out[8]//TableForm=
2 3
1 y y y
1 a 0 0 e
x 0 0 d 0
2
x 0 c 0 0
3
x b 0 0 0
HTH,
Jean-Marc
===
Subject: Re: Re: How to choose real positive solutions only?
===
Subject: Re:Re: Normal for Limit
I think I've got it sussed out now:
is equivalent to
If x=a is not a singularity of f[x], then
Normal[f[x]+O[x,a]]
will do.
I reckon there's no Normal equivalent for
for poles of odd order.
Ajit.
===
Subject: Re: About function to evaluation
Hi
modify the function f for simplicity
f[x_,y_]:={x,y,2x+3y}
and then
data={{1,2,0},{2,3,0},{4,1,0},{6,3,0},{1,3,0}}
and
myResult=(f@@Reverse[Most[#]])&/@data
generate the list and
TableForm[myResult,TableHeadings[Rule]{None,{x,y,f[x,y]}},
TableAlignments[Rule]Center]
generates the table
yehuda
===
Subject: Re: notebook as TXT
Hallo, I can discern TeX and TXT format :-)
There are two exaples:
*.m file :
-----------------
(*
Clear[`*];
R = 0.3;
G = 80*10^9;
EE = 206*10^9;
ro = 7830;
.....
----------------
The same file with addition line with special characters:
-------------------------
(*
!(*
RowBox[{[IndentingNewLine],
(G = 80*10^9;), n, (EE = 206*10^9;), n, (ro =
7830;),
.....
------------------------
It's interesting, because the special forms
---------------------------------------------------
(!(*
RowBox[{
SuperscriptBox[ET,
TagBox[((0, 1)),
Derivative],
---------------------------------------------------
added to second example was in the end of file,
In notebook this form looks like ET(0,1)[t,0] - where (0,1) is upper index
(d/dx)
After adding it ALL the file becomes to unreadable (TXT or PACKAGE *.m)
===
Subject: Re: Mathematica function for Chi Square Test...
The basic idea is to compare frequency of data within bins with expected
frequency within those same bins. The test statistic of interest is
Total[(observedcounts - expectedcounts)^2/expectedcounts]
If the expected counts are not based on a parametric distribution, this
statistic follows a chi square distribution with
Length[observedcounts]-1 degrees of freedom. If the expected counts are
based on fitting to a parametric distribution (and some regularity
conditions apply), there are Length[observedcounts]-NumberOfParameters-1
degrees of freedom.
Starting with lists of observed and expected counts, the process is
pretty straightforward. In the parametric case, there is a question of
how best to subdivide the region into bins and how many bins.
Additionally, the parameters need to be estimated (typically by
minimizing the chi-square statistic above with respect to the parameters).
The following uses equal width bins as a demonstration (and assumes
necessary regularity conditions hold). There may be reason to use
unequal bins in your case, but I do not know the details for suggested
binning of data.
First simulate some data:
In[1]:= <