Message Boards Message Boards

How to write system of differential equations in Mathematica with index?

Posted 2 years ago

Hello, I am new to Mathematica. I was trying to write a system of differential equations in Mathematica but no success so far. My system is in vector form with index like.. enter image description here

Further, I want to expand x_ n in series form as x_ n=x_ n0 +x_ n1+x_ n2+....... Can someone help me how can I write this?

Thanks in advance.

POSTED BY: ver din
4 Replies

This is a way:

DSolve[{Subscript[x, 1]'[t] == -Subscript[x, 1][t] + 
    Subscript[x, 2][t], 
  Subscript[x, 2]'[t] == 
   Subscript[x, 1][t] - Subscript[x, 2][t]}, {Subscript[x, 1][t], 
  Subscript[x, 2][t]}, t]
POSTED BY: Gianluca Gorni

General solution:

DSolve[{x1'[t] == -x1[t] + x2[t], x2'[t] == x1[t] - x2[t]}, {x1[t], x2[t]}, t]
  (*{{x1[t] -> 
     1/2 E^(-2 t) (1 + E^(2 t)) C[1] + 1/2 E^(-2 t) (-1 + E^(2 t)) C[2],
     x2[t] -> 
     1/2 E^(-2 t) (-1 + E^(2 t)) C[1] + 
      1/2 E^(-2 t) (1 + E^(2 t)) C[2]}}*)

Or:

A = {{-1, 1}, {1, -1}};
DSolve[x'[t] == A . x[t], x[t] \[Element] Vectors[2], t]
(*{{x[t] -> {1/2 E^(-2 t) (1 + E^(2 t)) C[1] + 
     1/2 E^(-2 t) (-1 + E^(2 t)) C[2], 
    1/2 E^(-2 t) (-1 + E^(2 t)) C[1] + 
     1/2 E^(-2 t) (1 + E^(2 t)) C[2]}}}*)

Solution by series:

AsymptoticDSolveValue[{x1'[t] == -x1[t] + x2[t], 
  x2'[t] == x1[t] - x2[t]}, {x1[t], x2[t]}, {t, 0, 5}]
(*{(1 - t + t^2 - (2 t^3)/3 + t^4/3 - (2 t^5)/15) C[
   1] + (t - t^2 + (2 t^3)/3 - t^4/3 + (2 t^5)/15) C[
   2], (t - t^2 + (2 t^3)/3 - t^4/3 + (2 t^5)/15) C[
   1] + (1 - t + t^2 - (2 t^3)/3 + t^4/3 - (2 t^5)/15) C[2]}*)
POSTED BY: Mariusz Iwaniuk
Posted 2 years ago

Thanks for the answer. However, it does not serve my purpose as I want to write x_ n[t] in index form, so that I can apply "For" loop on index "n" and process my set of equations through several operations at the same time. Is there any remedy? Thanks in advance.

POSTED BY: ver din

Another way:

 DSolve[{x[1]'[t] == -x[1][t] + x[2][t], x[2]'[t] == x[1][t] - x[2][t]}, {x[1][t], x[2][t]}, t]
POSTED BY: Mariusz Iwaniuk
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