Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #3190 > unrolled thread
| Started by | Jacare Omoplata <walkeystalkey@gmail.com> |
|---|---|
| First post | 2011-06-19 23:29 +0000 |
| Last post | 2011-06-25 09:31 +0000 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
How to find one expression in terms of another expression? Jacare Omoplata <walkeystalkey@gmail.com> - 2011-06-19 23:29 +0000
Re: How to find one expression in terms of another expression? Ray Koopman <koopman@sfu.ca> - 2011-06-20 23:37 +0000
Re: How to find one expression in terms of another expression? Jacare Omoplata <walkeystalkey@gmail.com> - 2011-06-21 11:18 +0000
Multiple use of Set on lists Jonathan Frazer <J.Frazer@sussex.ac.uk> - 2011-06-20 23:38 +0000
Re: Multiple use of Set on lists Oleksandr Rasputinov <oleksandr_rasputinov@hmamail.com> - 2011-06-21 11:17 +0000
Re: Multiple use of Set on lists Leonid Shifrin <lshifr@gmail.com> - 2011-06-25 09:31 +0000
| From | Jacare Omoplata <walkeystalkey@gmail.com> |
|---|---|
| Date | 2011-06-19 23:29 +0000 |
| Subject | How to find one expression in terms of another expression? |
| Message-ID | <itm0of$143$1@smc.vnet.net> |
I want to find dT in terms of dt. They are given below.
In[1]:= Element[{x1, x2, t1, t2, u, c}, Reals]
Out[1]= (x1 | x2 | t1 | t2 | u | c) \[Element] Reals
In[3]:= T1 = (t1 - ((u x1)/c^2))/Sqrt[1 - (u^2/c^2)]
Out[3]= (t1 - (u x1)/c^2)/Sqrt[1 - u^2/c^2]
In[4]:= T2 = (t2 - ((u x2)/c^2))/Sqrt[1 - (u^2/c^2)]
Out[4]= (t2 - (u x2)/c^2)/Sqrt[1 - u^2/c^2]
In[5]:= dT = T2 - T1
Out[5]= -((t1 - (u x1)/c^2)/Sqrt[1 - u^2/c^2]) + (
t2 - (u x2)/c^2)/Sqrt[1 - u^2/c^2]
In[6]:= dt = t2 - t1
Out[6]= -t1 + t2
If I knew that dT can be written in terms of dt in the form,
dT = a dt + b,
Can I use Mathematica to find a and b?
I tried using Solve[dT == a dt + b, dt], but that gives an error.
If I didn't know that dT can be expressed this way, can I still
express it in terms of dt ?
[toc] | [next] | [standalone]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2011-06-20 23:37 +0000 |
| Message-ID | <itolk6$er6$1@smc.vnet.net> |
| In reply to | #3190 |
On Jun 19, 4:29 pm, Jacare Omoplata <walkeystal...@gmail.com> wrote:
> I want to find dT in terms of dt. They are given below.
>
> In[1]:= Element[{x1, x2, t1, t2, u, c}, Reals]
>
> Out[1]= (x1 | x2 | t1 | t2 | u | c) \[Element] Reals
>
> In[3]:= T1 = (t1 - ((u x1)/c^2))/Sqrt[1 - (u^2/c^2)]
>
> Out[3]= (t1 - (u x1)/c^2)/Sqrt[1 - u^2/c^2]
>
> In[4]:= T2 = (t2 - ((u x2)/c^2))/Sqrt[1 - (u^2/c^2)]
>
> Out[4]= (t2 - (u x2)/c^2)/Sqrt[1 - u^2/c^2]
>
> In[5]:= dT = T2 - T1
>
> Out[5]= -((t1 - (u x1)/c^2)/Sqrt[1 - u^2/c^2]) + (
> t2 - (u x2)/c^2)/Sqrt[1 - u^2/c^2]
>
> In[6]:= dt = t2 - t1
>
> Out[6]= -t1 + t2
>
> If I knew that dT can be written in terms of dt in the form,
> dT = a dt + b,
> Can I use Mathematica to find a and b?
>
> I tried using Solve[dT == a dt + b, dt], but that gives an error.
>
> If I didn't know that dT can be expressed this way,
> can I still express it in terms of dt ?
Omit 'dt = t2 - t1'. Otherwise, every time you write 'dt'
it will be replaced by 't2 - t1'. Here is all you need:
In[1]:=
T1 = (t1 - ((u x1)/c^2))/Sqrt[1 - (u^2/c^2)];
T2 = (t2 - ((u x2)/c^2))/Sqrt[1 - (u^2/c^2)];
dT = Simplify[T2 - T1] /. t2 - t1 -> dt
{b,a} = CoefficientList[dT,dt]
Out[3]= (c^2*dt + u*(x1 - x2))/(c^2*Sqrt[1 - u^2/c^2])
Out[4]= {(u*(x1 - x2))/(c^2*Sqrt[1 - u^2/c^2]), 1/Sqrt[1 - u^2/c^2]}
[toc] | [prev] | [next] | [standalone]
| From | Jacare Omoplata <walkeystalkey@gmail.com> |
|---|---|
| Date | 2011-06-21 11:18 +0000 |
| Message-ID | <itpuma$m0o$1@smc.vnet.net> |
| In reply to | #3199 |
Thanks for this answer.
On Jun 20, 7:37 pm, Ray Koopman <koop...@sfu.ca> wrote:
>
> Omit 'dt = t2 - t1'. Otherwise, every time you write 'dt'
> it will be replaced by 't2 - t1'. Here is all you need:
>
> In[1]:=
> T1 = (t1 - ((u x1)/c^2))/Sqrt[1 - (u^2/c^2)];
> T2 = (t2 - ((u x2)/c^2))/Sqrt[1 - (u^2/c^2)];
> dT = Simplify[T2 - T1] /. t2 - t1 -> dt
> {b,a} = CoefficientList[dT,dt]
>
> Out[3]= (c^2*dt + u*(x1 - x2))/(c^2*Sqrt[1 - u^2/c^2])
>
> Out[4]= {(u*(x1 - x2))/(c^2*Sqrt[1 - u^2/c^2]), 1/Sqrt[1 - u^2/c^2]}
[toc] | [prev] | [next] | [standalone]
| From | Jonathan Frazer <J.Frazer@sussex.ac.uk> |
|---|---|
| Date | 2011-06-20 23:38 +0000 |
| Subject | Multiple use of Set on lists |
| Message-ID | <itolks$erm$1@smc.vnet.net> |
| In reply to | #3190 |
Hello,
I have a largish list of awkwardly "indexed variables", of the form cs =
{c[1/2][-(1/2)][1/2][-(1/2)][-1], c[1/2][-(1/2)][1/2][1/2][-1]......etc....
....} which need to be assigned random values multiple times inside a Do loop. I was hoping I could generate a new list of random numbers each time then do something like
MapThread[Set, {cs, rands}]
Where "rands" would be the list of random numbers. I'm clearly misunderstanding how MapThread works though as this doesn't work. Rather than getting "c[1/2][-(1/2)][1/2][-(1/2)][-1]=new random number", instead "old random number=new random number" is what seems to be happening.
As a last resort I thought I would just clear the variables at the beginning of the do loop but you can't use Clear to do this and I don't see how you can apply "=." (Unset) over a list either.
Any suggestions?
Many thanks,
Jonny
[toc] | [prev] | [next] | [standalone]
| From | Oleksandr Rasputinov <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-06-21 11:17 +0000 |
| Subject | Re: Multiple use of Set on lists |
| Message-ID | <itpul0$m09$1@smc.vnet.net> |
| In reply to | #3201 |
The problem is due to Set being HoldFirst but MapThread not having any
corresponding Hold attributes. While the c's are being substituted for their values too early, this is not an issue with MapThread per se; rather it is a consequence of how attributes affect the order of evaluation in Mathematica.
An ugly hack which solves the problem as stated is the following:
SubValues[c] = Block[{c},
MapThread[Set, {cs, rands}];
SubValues[c]
];
However, it may be better to reformulate the problem in such a way
that this construct is not needed.
On Jun 21, 12:38 am, Jonathan Frazer <J.Fra...@sussex.ac.uk> wrote:
> Hello,
>
> I have a largish list of awkwardly "indexed variables", of the form cs =
> {c[1/2][-(1/2)][1/2][-(1/2)][-1], c[1/2][-(1/2)][1/2][1/2][-1]......etc....
> ....} which need to be assigned random values multiple times inside a Do loop. I was hoping I could generate a new list of random numbers each time then do something like
>
> MapThread[Set, {cs, rands}]
>
> Where "rands" would be the list of random numbers. I'm clearly misunderstanding how MapThread works though as this doesn't work. Rather than getting "c[1/2][-(1/2)][1/2][-(1/2)][-1]=new random number", instead "old random number=new random number" is what seems to be happening.
>
> As a last resort I thought I would just clear the variables at the beginning of the do loop but you can't use Clear to do this and I don't see how you can apply "=." (Unset) over a list either.
>
> Any suggestions?
>
> Many thanks,
>
> Jonny
[toc] | [prev] | [next] | [standalone]
| From | Leonid Shifrin <lshifr@gmail.com> |
|---|---|
| Date | 2011-06-25 09:31 +0000 |
| Subject | Re: Multiple use of Set on lists |
| Message-ID | <iu49u8$jph$1@smc.vnet.net> |
| In reply to | #3190 |
Here is a bit less exotic solution:
Set @@@ Append @@@
Transpose[{Thread[Hold[cs] /. OwnValues[cs]], rands}]
You may try for example with
cs = {c[1/2][-(1/2)][1/2][-(1/2)][-1], c[1/2][-(1/2)][1/2][1/2][-1]}
rands = {1,2}
but I'd agree that it may be better to reformulate the problem.
Regards,
Leonid
On Tue, Jun 21, 2011 at 1:51 PM, Oleksandr Rasputinov <
oleksandr_rasputinov@hmamail.com> wrote:
> The problem is due to Set being HoldFirst but MapThread not having any
> corresponding Hold attributes. While the c's are being substituted for
> their values too early, this is not an issue with MapThread per se; rather
> it is a consequence of how attributes affect the order of evaluation in
> Mathematica.
>
> An ugly hack which solves the problem as stated is the following:
>
> SubValues[c] = Block[{c},
> MapThread[Set, {cs, rands}];
> SubValues[c]
> ];
>
> However, it may be better to reformulate the problem in such a way
> that this construct is not needed.
>
> On Jun 21, 12:38 am, Jonathan Frazer <J.Fra...@sussex.ac.uk> wrote:
> > Hello,
> >
> > I have a largish list of awkwardly "indexed variables", of the form cs =
> > {c[1/2][-(1/2)][1/2][-(1/2)][-1],
> c[1/2][-(1/2)][1/2][1/2][-1]......etc....
> > ....} which need to be assigned random values multiple times inside a Do
> loop. I was hoping I could generate a new list of random numbers each time
> then do something like
> >
> > MapThread[Set, {cs, rands}]
> >
> > Where "rands" would be the list of random numbers. I'm clearly
> misunderstanding how MapThread works though as this doesn't work. Rather
> than getting "c[1/2][-(1/2)][1/2][-(1/2)][-1]=new random number", instead
> "old random number=new random number" is what seems to be happening.
> >
> > As a last resort I thought I would just clear the variables at the
> beginning of the do loop but you can't use Clear to do this and I don't see
> how you can apply "=." (Unset) over a list either.
> >
> > Any suggestions?
> >
> > Many thanks,
> >
> > Jonny
>
>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web