0
$\begingroup$

I come from python (not advanced tho), and have been learning mathematica. I'm currently struggling with the following code:

This is a basic version of what i wanted to implement:

Ni = 5
Na = 2
(mtrix = {{a, b, c}, {d, e, f}, {g, h, i}}) // MatrixForm
mr = Flatten[Table[Mr[i, j, 0] = M0, {i, 1, Ni}, {j, 1, Na}], 1]
NestList[Map[Function[x, mtrix.x], #] &, mr, 3]

Now is the clue, that I want to replace the basic matrix with a very complex matrix function taking multiple arguments

Rp[α/(γ τ), 0, Δω[Grd, r[i]], τ]

for which (I think this piece is not crucial to look at, the main issue arrises from the r[i] for me)

Rx[α_] := ( {
    {1, 0, 0},
    {0, Cos[α], Sin[α]},
    {0, -Sin[α], Cos[α]}
   } );
Ry[α_] := ( {
    {Cos[α], 0, -Sin[α]},
    {0, 1, 0},
    {Sin[α], 0, Cos[α]}
   } );
Rz[α_] := ( {
    {Cos[α], Sin[α], 0},
    {-Sin[α], Cos[α], 0},
    {0, 0, 1}
   } ); 

R[ϕ_, θ_, α_] :=  Rz[ϕ].Ry[θ].Rx[α].Ry[-θ].Rz[-ϕ];

Rp[B1_, ϕ_, Δω_, Δt_] := R[ϕ, θeff[Δα[B1, Δt], Δω, Δt], αeff[Δα[B1, Δt], Δω,  Δt]];

Δω[G_, r_] := γ G r;

α = 90;
γ = 2 π 42.56 10^6;

ms = 10^-3;
mTm = 10^-3;
Δx = 0.1 mm;

τ = 0.01 ms;
[i_] := (i - Round[Ni/2] - 1) Δx;
Grd = 0.5 mTm;

So, something like this:

NestList[Map[Function[x, Rp[α/(γ τ), 0, Δω[Grd, r[i]], τ].x], #] &, mr, 3]

But how do I handle the i in the r[i]?

I hope this makes a bit of sense, any help in welcome,

thanx

Jenny

$\endgroup$
  • $\begingroup$ This definition [i_] := (i - Round[Ni/2] - 1) \[CapitalDelta]x; is incomplete. $\endgroup$ – Anton Antonov Jun 29 '18 at 23:41
  • $\begingroup$ "But how do I handle the i in the r[I]?" -- It seems to me you have use FoldList. For example, FoldList[Map[ Function[x, Rp[\[Alpha]/(\[Gamma] \[Tau]), 0, \[CapitalDelta]\[Omega][Grd, r[#2]], \[Tau]].x], #1] &, mr, {1, 2, 3}]. $\endgroup$ – Anton Antonov Jun 29 '18 at 23:45
  • $\begingroup$ Sorry, [CapitalDelta]x = 0.1 mm; . Thanx i will try! $\endgroup$ – jenny Jun 30 '18 at 1:17
  • $\begingroup$ jenny, your second to last line ( [i_] := (i - Round[Ni/2] - 1) \[CapitalDelta]x;) is missing the function name. $\endgroup$ – kglr Jun 30 '18 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.