Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting vector equation to a list of equations in Mathematica

Due to DSolve syntax, systems of differential equations have to be given as lists of equations and not as a vector equation (Unlike Solve, which accepts both). So my simple question is how to convert a vector equation such as:

{f'[t],g'[t]}=={{a,b},{c,d}}.{f[t],g[t]}

To list of equations:

{f'[t]==a*f[t]+b*g[t],g'[t]==c*f[t]+d*g[t]}

I think I knew once the answer, but I can't find it now and I think it could benefit others as well.

like image 958
Yuval Elhanati Avatar asked Dec 15 '10 16:12

Yuval Elhanati


People also ask

How do you convert from vector to general form?

The normal form of the equation of a line l in R2 is n · (x - p)=0, or n · x = n · p where p is a specific point on l and n = 0 is a normal vector for l. The general form of the equation of l is ax + by = c where n = [a b ] is a normal vector for l. Example 0.5. Let us find the vector form of the previous example.

What is DSolve command in Mathematica?

DSolve[eqn,u[x,y],{x,y}] solve a partial differential equation for. Finding symbolic solutions to partial differential equations. While general solutions to ordinary differential equations involve arbitrary constants, general solutions to partial differential equations involve arbitrary functions.

What is a list in Mathematica?

Lists are very general objects that represent collections of expressions. Functions with attribute Listable are automatically "threaded" over lists, so that they act separately on each list element. Most built‐in mathematical functions are Listable.


2 Answers

Try using Thread:

Thread[{f'[t], g'[t]} == {{a, b}, {c, d}}.{f[t], g[t]}]
(* {f'[t] == a f[t] + b g[t], g'[t] == c f[t] + d g[t] *)

It takes the equality operator == and applies it to each item within a list with the same Head.

like image 65
Brett Champion Avatar answered Oct 17 '22 06:10

Brett Champion


The standard answer to this question is that which Brett presented, i.e., using Thread. However, I find that for use in DSolve, NDSolve, etc... the command LogicalExpand is better.

eqn = {f'[t], g'[t]} == {{a, b}, {c, d}}.{f[t], g[t]};

LogicalExpand[eqn]

(* f'[t] == a f[t] + b g[t] && g'[t] == c f[t] + d g[t] *)

It doesn't convert a vector equation to a list, but it is more useful since it automatically flattens out matrix/tensor equations and combinations of vector equations. For example, if you wanted to add initial conditions to the above differential equation, you'd use

init = {f[0], g[0]} == {f0, g0};

LogicalExpand[eqn && init]

(* f[0] == f0 && g[0] == g0 && 
  f'[t] == a f[t] + b g[t] && g'[t] == c f[t] + d g[t] *)

An example of a matrix equation is

mEqn = Array[a, {2, 2}] == Partition[Range[4], 2];

Using Thread here is awkward, you need to apply it multiple times and Flatten the result. Using LogicalExpand is easy

LogicalExpand[mEqn]

(* a[1, 1] == 1 && a[1, 2] == 2 && a[2, 1] == 3 && a[2, 2] == 4 *)
like image 31
Simon Avatar answered Oct 17 '22 06:10

Simon