Message Boards Message Boards

NDSolve error for a system of coupled differential equations

Hello all,

I am trying to solve LLG equation for a 2 spin system. When I add vector B to effective field Heff I get error 'The arguments are expected to be vectors of equal length, and the number of arguments is expected to be 1 less than their length.' I see that Assumptions in the beginning is not helping me. Can some one tell me how to define m(t) as a vector in the beginning? Please find my code pasted below.

gamma = 1;
alphag = 0.1;
Beff = {0, 0, 10};
z = {0, 0, 1}
J = -1;

B = {0, 1, 0};

$Assumptions = (m[t] | m1[t]) \[Element] Vectors[3, Reals];

Heff[t_] := J*m1[t] + B;
Heff1[t_] := J*m[t]  + B;
cons[t_] := Cross[m[t], Heff[t]];
cons1[t_] := Cross[m1[t], Heff1[t]];

tGilbdamp[t_] := alphag*Cross[m[t], cons[t]];
tGilbdamp1[t_] := alphag*Cross[m1[t], cons1[t]];

tmax = 100;
LLGS = {m'[t] == -gamma*{cons[t] + tGilbdamp[t]}, 
   m[0] == Normalize[{-Sqrt[3.]/2, -1/2, 0}]};
LLGS1 = {m1'[t] == -gamma*{cons1[t] + tGilbdamp1[t]}, 
   m1[0] == Normalize[{Sqrt[3.]/2, -1/2, 0}]};

sol1 = NDSolve[{LLGS, LLGS1}, {m, m1,}, {t, 0, tmax}]


Plot[Evaluate[m[t] /. sol1[[1]]], {t, 0, tmax}]
Plot[Evaluate[m1[t] /. sol1[[1]]], {t, 0, tmax}]
POSTED BY: Akshay S
4 Replies

Unfortunately, as documented under Vectors, assuming that a symbol is a vector is not compatible with listable operations with explicit vectors:

In[1]:= Assuming[v \[Element] Vectors[2], v + {1, 2}]

Out[1]= {1 + v, 2 + v}

Hence, your definition Heff[t_] := J*m1[t] + B does not work as we would somehow expect.

You can work around the limitation this way:

gamma = 1; alphag = 0.1; Beff = {0, 0, 10}; z = {0, 0, 1};
J = -1; B = {0, 1, 0};
$Assumptions = (m[t] | m1[t]) \[Element] Vectors[3, Reals];
cons[t_] = Cross[m[t], J*m1[t]] + Cross[m[t], B];
cons1[t_] = Cross[m1[t], J*m[t]] + Cross[m1[t], B];
tGilbdamp[t_] := alphag*Cross[m[t], cons[t]];
tGilbdamp1[t_] := alphag*Cross[m1[t], cons1[t]];
tmax = 100;
LLGS = {m'[t] == -gamma*{cons[t] + tGilbdamp[t]}, 
   m[0] == Normalize[{-Sqrt[3.]/2, -1/2, 0}]};
LLGS1 = {m1'[t] == -gamma*{cons1[t] + tGilbdamp1[t]}, 
   m1[0] == Normalize[{Sqrt[3.]/2, -1/2, 0}]};

sol1 = NDSolve[{LLGS, LLGS1}, {m, m1}, {t, 0, tmax}]
POSTED BY: Gianluca Gorni

Hi Gianluca Gorni,

Thank you very much. The code works now with the modifications you suggested.

Best Regards Akshay

POSTED BY: Akshay S
Posted 3 years ago

Try this modification.

Notice I changed two {} to ()

gamma = 1; alphag = 0.1; Beff = {0, 0, 10}; z = {0, 0, 1}; J = -1;B = {0, 1, 0};
Heff[t_] := J*{m1x[t],m1y[t],m1z[t]} + B;
Heff1[t_] := J*{mx[t],my[t],mz[t]} + B;
cons[t_] := Cross[{mx[t],my[t],mz[t]}, Heff[t]];
cons1[t_] := Cross[{m1x[t],m1y[t],m1z[t]}, Heff1[t]];
tGilbdamp[t_] := alphag*Cross[{mx[t],my[t],mz[t]}, cons[t]];
tGilbdamp1[t_] := alphag*Cross[{m1x[t],m1y[t],m1z[t]}, cons1[t]];
tmax = 100;
LLGS = {{mx'[t],my'[t],mz'[t]} == -gamma*(cons[t] + tGilbdamp[t]),
{mx[0],my[0],mz[0]} == Normalize[{-Sqrt[3.]/2, -1/2, 0}]};
LLGS1 = {{m1x'[t],m1y'[t],m1z'[t]} == -gamma*(cons1[t] + tGilbdamp1[t]),
{m1x[0],m1y[0],m1z[0]} == Normalize[{Sqrt[3.]/2, -1/2, 0}]};
sol1 = NDSolve[{LLGS, LLGS1}, {mx[t],my[t],mz[t],m1x[t],m1y[t],m1z[t]}, {t,0,tmax}]

That doesn't give any errors and seems to come up with solutions.

Please check that very carefully to make certain that I have not made any mistakes or misunderstood what you were trying to do.

POSTED BY: Bill Nelson

Hi Bill Nelson,

Thank you very much. It works perfectly now.

Best Regards Akshay

POSTED BY: Akshay S
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract