3
$\begingroup$

Is it possible to solve an ODE in state-space form in mathematica? Such as

 x'[t]=A.x[t]

I attempted

w = 2; 
T = 2 Pi/w;
a = 0.4; b = 4.0; d = 0.3;

A = T {{0, 1}, {-a - b Cos[2 t], -d}}

x[t_] := {x1[t], x2[t]}
sol = NDSolve[{x'[t] == A.x[t], x[0] == x'[0] == 0}, x, {t, 0, 1}]

but received the error

NDSolve::icfail: Unable to find initial conditions that satisfy the residual function within specified tolerances. Try giving initial conditions for both values and derivatives of the functions. 
$\endgroup$
  • 1
    $\begingroup$ I do not know why the numerical gives these warnings, but your solutions are zero according to DSolve: w = 2; T = 2 Pi/w; a = 0.4; b = 4.0; d = 0.3; x[t_] := {x1[t], x2[t]} A0 = T {{0, 1}, {-a - b Cos[2 t], -d}}; sol = DSolve[{x'[t] == A0.x[t], x[0] == x'[0] == 0}, x[t], t] which gives {{x1[t] -> 0, x2[t] -> 0}} on V 10.1 $\endgroup$ – Nasser Apr 6 '15 at 16:37
5
$\begingroup$

I ve modified slightly your problem to one which works:

I used exact numbers

w = 2;
T = 2 Pi/w;
a = 4/10; b = 4; d = 3/10;

A = T {{0, 1}, {-a - b Cos[2 t], -d}}

I then drop the Initial condition on derivatives which are redundant given the order of your equation:

sol = NDSolve[{x'[t] == A.x[t], x[0] == {1, 2}},x[t] , {t, 0, 1}]

then I plot the result

 ParametricPlot[x[t] /. sol, {t, 0, 1}]

Mathematica graphics

Update

If you insist on {0,0} as initial conditions you get (as @nasser points out)

 sol = DSolve[{x'[t] == A.x[t], x[0] == {0, 0}}, x[t], {t, 0, 1}]

(* {{x1(t)->0,x2(t)->0}} *)

Update 2

Just for fun mathematica can write the general solution for arbitrary ICs

T=a=b=d=.;
A = T {{0, 1}, {-a - b Cos[2 t], -d}}
x[t_] := {x1[t], x2[t]}
sol = DSolve[{x'[t] == A.x[t], 
    x[0] == {a1,a2}}, x[t], t] // 
  FullSimplify

Mathematica graphics

$\endgroup$
  • $\begingroup$ That's perfect, thanks! No need for {0,0}, I just chose at random. $\endgroup$ – gKirkland Apr 6 '15 at 16:43
  • $\begingroup$ you are welcome… $\endgroup$ – chris Apr 6 '15 at 16:44
3
$\begingroup$

If you wanted to use StateSpaceModel to implement the solution, you could do the following

ssm = StateSpaceModel[
  {x1'[t] == Pi x2[t],
   x2'[t] == Pi (-a - b Cos[2 t]) x1[t] - d Pi x2[t]},
  {{x1[t], 0}, {x2[t], 0}, {x1'[t], 0}, {x2'[t], 0}},
  {{u[t], 0}},
  {x1[t], x2[t]},
  t
  ]

enter image description here

Then find the StateResponse

response = StateResponse[{ssm, {1, 2}}, {UnitStep[t]}, {t, 0, 1}]

Out: {InterpolatingFunction[][t], InterpolatingFunction[][t]}

And then ParametricPlot it

ParametricPlot[response, {t, 0, 1}]

enter image description here

$\endgroup$

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.