1
$\begingroup$

the following code fail to multiply each equation by dt, since dt does not seem to do any jobs. it remains as a common factor, I would like it to cancel out the 1/dt term and also multiply the rest of them with dt.

eqns = {x1'[t] == (\[Mu] - (x1^2 + x2^2)) x1 - x3x2 + 
    Ksin + \[Sigma]dw/dt, 
  x2'[t] == (\[Mu] - (x1^2 + x2^2)) x2 + (x3x1), 
  x3'[t] == -(Ksin + \[Sigma]dw/dt) x2}

sort1 = eqns /. {x1'[t] -> dx1/dt, x2'[t] -> dx2/dt, 
    x3'[t] -> dx3/dt} // MatrixForm

sort2 = sort1*dt

what I would like to see is

dx1 == dt Ksin - dt x1^3 - dt x1 x2^2 - dt x3x2 + 
  dt x1 \[Mu] + \[Sigma]dw
dx2 == -dt x1^2 x2 - dt x2^3 + x3x1dt + dt x2 \[Mu]
dx3 == -x2 (dt Ksin + \[Sigma]dw)

besides,if it works as what I expect, how can you extract the terms/coefficients that includes the dt and dw seperately? it should look like the following expressions

dx1=dt(Ksin-x1^3-x1x2^2-x3x2+x1\[Mu])+(\[Sigma])dw)
dx2 == dt(-x1^2 x2 - x2^3 + x3x1 + x2 \[Mu])
dx3 == -dt(Ksin) + (\[Sigma])dw

if possible, can we make them as a matrix form?

since I would like to use the following terms elsewhere to do some other analysis

Ksin-x1^3-x1x2^2-x3x2+x1\[Mu]
-x1^2 x2 - x2^3 + x3x1 + x2 \[Mu]

Sincerely, Li

$\endgroup$
  • $\begingroup$ does it work if you replace sort1 = eqns /. {x1'[t] -> dx1/dt, x2'[t] -> dx2/dt, x3'[t] -> dx3/dt} // MatrixForm with (sort1 = eqns /. {x1'[t] -> dx1/dt, x2'[t] -> dx2/dt, x3'[t] -> dx3/dt}) // MatrixForm ? The MatrixForm is a wrapper which gets in the way of your computation. This is a common problem. If this still does not solve your problem, you could update the question with corrected code. $\endgroup$ – Nasser Apr 17 at 21:29
  • $\begingroup$ unfortunately, it does not work. do you have any other solutions? $\endgroup$ – xiaofu li Apr 18 at 17:58
1
$\begingroup$

EDIT: Better yet, use MultiplySides (which I learned about from this answer).

eqns = {x1'[t] == (\[Mu] - (x1^2 + x2^2)) x1 - x3 x2 + Ksin + \[Sigma]dw/dt,
        x2'[t] == (\[Mu] - (x1^2 + x2^2)) x2 + x3 x1,
        x3'[t] == -(Ksin + \[Sigma] dw/dt) x2};
sort = First@Solve[eqns, {x1'[t], x2'[t], x3'[t]}] /. Rule -> Equal;
sort2 = MultiplySides[sort, dt, Assumptions -> dt != 0];
sort3 = sort2 /. {x1'[t] -> dx1/dt, x2'[t] -> dx2/dt, x3'[t] -> dx3/dt} // TableForm

which produces

{
 {dx1 == dt Ksin - dt x1^3 - dt x1 x2^2 - dt x2 x3 + dt x1 \[Mu] + \[Sigma]dw},
 {dx2 == dt (-x1^2 x2 - x2^3 + x1 x3 + x2 \[Mu])},
 {dx3 == -x2 (dt Ksin + dw \[Sigma])}
}

To extract coefficients do the following

beloweqns1 = {dx1/dt == (a + b + c) dt + (e + f) dw, 
              x2/dt == (a1 + a2 + a3) dt + (e1 + e2) dw};
Coefficient[beloweqns1[[1, 2]], dt]
Coefficient[beloweqns1[[1, 2]], dw]
Coefficient[beloweqns1[[2, 2]], dt]
Coefficient[beloweqns1[[2, 2]], dw]

To understand the indexing on beloweqns above, use TreeForm[beloweqns].


I think you want to use

Distribute[sort1*dt, Equal]

because otherwise Mathematica treats the equation as a symbolic object.

| improve this answer | |
$\endgroup$
  • $\begingroup$ unfortunately, I tried MultiplySides and the Distribute as mentioned above, none of them work. can you give me some other feasible solutions? but still, thanks a lot for the help. $\endgroup$ – xiaofu li Apr 18 at 17:59
  • $\begingroup$ Hi dskeletov, eventually, I figured it out how to make it work. the following is my new code, I hope that it could be helpful for other people.eqns = {x1'[t] == (\[Mu] - (x1^2 + x2^2)) x1 - x3x2 + Ksin + \[Sigma]dw/dt, x2'[t] == (\[Mu] - (x1^2 + x2^2)) x2 + x3x1, x3'[t] == -(Ksin + \[Sigma]dw/dt) x2}, sort = First@Solve[eqns, {x1'[t], x2'[t], x3'[t]}] /. Rule -> Equal, sort2 = MultiplySides[sort, dt, Assumptions -> dt != 0], sort3 = sort2 /. {x1'[t] -> dx1/dt, x2'[t] -> dx2/dt, x3'[t] -> dx3/dt} // MatrixForm $\endgroup$ – xiaofu li Apr 18 at 18:20
  • $\begingroup$ unfortunately, I also could not factor out dt and dw in those equations, since I would like the coefficients elsewhere when you factor them out. thanks again for those who provide me with some help. $\endgroup$ – xiaofu li Apr 18 at 18:24
  • $\begingroup$ I don't understand your last comment, xiaofu, but I'm glad that it seems to work. I'm going to copy your code into my answer to make it more complete. $\endgroup$ – dskeletov Apr 18 at 22:22
  • $\begingroup$ Hi dskeletov, no problem, please make the answer complete, so that everyone could learn it, besides as for the new question, if you have a system equations as shown beloweqns1 = {dx1/dt == (a + b + c) dt + (e + f) dw, x2/dt == (a1 + a2 + a3) dt + (e1 + e2) dw} // MatrixForm, how can you extract the a+b+c, a1+a2+a3 and e+f from the eqns1? since I do not want to copy the answer from the output of the eqns1. $\endgroup$ – xiaofu li Apr 18 at 22:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.