Re: Mathematica Programming Problem
- To: mathgroup at smc.vnet.net
- Subject: [mg42580] Re: [mg42539] Mathematica Programming Problem
- From: Dr Bob <drbob at bigfoot.com>
- Date: Wed, 16 Jul 2003 09:13:41 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
It's impossible to tell what the problem is, as you've left out a bracket
in defining T2 for us.
First I assumed it belonged at the end, and T2[3] was Null.
When I put the bracket just after j++, the answer changed to {3, 2, 1}.
I was unable to duplicate the answer you got.
>> P[x_] := Part[T1[n], j]
You haven't made P[x] depend on x, so P[t+n-j] doesn't depend on t+n-j.
Maybe you meant
P[x_] := Part[T1[x], j];
>> But,the actual answer should have variable t inside, isn't it?
No. P[t+n-j] is a Part of T1[n], and T1 doesn't involve the variable t.
>> list1=PrependTo[list1,y]
"list1=" is unnecessary here, as PrependTo resets its first argument.
>>
Here's a simpler definition for T1:
t1[n_Integer?Positive] := Table[Sum[
Binomial[n, i](x - i)^(n - 1), {i, m, n}], {m, n, 1, -1}]/(n - 1)!
T2 could be simplified similarly.
>> T2[n_] := Module[{list2 = {}, , j = 1}, While[j â?¤ n,
P[x_] := Part[T1[x], j];
list2 = PrependTo[list2, P[t + n - j];
j++]];
list2]
If that's what you intended T2 to be, a much simpler version would be:
t2[n_Integer?positive] := Table[t1[t + n - j][[j]], {j, n, 1, -1}]
But that doesn't work (and your version can't work) because t is undefined,
so t1[t+n-j] isn't the list of expressions you mean it to be.
Bobby
"Loh" <lohleeping at hotmail.com> wrote:
Hai,
I would like to ask something regarding programming in Mathematica.
Below is what I wrote in Mathematica,
T1[n_]:=Module[{list1={},i,m=1,y},
While[m<=n, =
y=1/(n-1)!Sum[Binomial[n,i](-1)^(n-i)(i-x)^(n-1),{i,m,n}];
list1=PrependTo[list1,y];
m++];
list1]
T2[n_]:=Module[{list2={},,j=1},
While[j<=n, P[x_]:=Part[T1[n],j];
list2=PrependTo[list2,P[t+n-j]; j++];
list2]
Can you please help me to look at T2. Is there any problem ?
When I run those function, it's ok. But when I key in T2[3],
the output is: { x^2/2, -3/2+3x-x^2, 9/2-3x+x^2/2 }.
But,the actual answer should have variable t inside, isn't it?
Please reply A.S.A.P.
Thank you very much.
Best regards,
Loh