(*  Koodinpatkia C3 - 05 mikro 2 : 
        een .     KE  *) 

 (*  Mieti,  mita koodi tekee,  
      mitenpain plotit menee jne ...  *) 
 (*  ... ja kayta tarpeen mukaan helppia komentojen selvittamiseksi  *)

(*   1   *)

a  =  {{1, 2}, {3, 4}}

Eigenvalues[a]

N[%]

Max[ Apply[ Plus,  Abs[%] ] ]

Max[ Apply[ Plus,  Abs[ Transpose[a] ] ] ]

a^2

N[ Apply[ Plus,  Flatten[a^2] ]^(1/2) ]

n = 100;
MatrixForm[ N[  MatrixPower[a, n] ] ]

N[ Apply[ Plus,  Flatten[%^2] ]^(1/2) ]

%^(1/100)

a = {{1, 1}, {1, 0}}

Eigenvalues[a]

MatrixPower[a,] . {1, 1}

n =  100;
MatrixForm[ 
      N[ MatrixPower[a, n]/(Eigenvalues[a][[ ]])^
            n] ]

Det[%]

sol = NDSolve[ {x'[t] == - .5x[t] - y[t], y'[t] == x[t] - y[t],
		x[0] == 3, y[0] == 1}, {x,y}, {t,10} ];

ParametricPlot[ Evaluate[ {x[t], y[t]} /. sol ],
		{t,0,10}, PlotRange -> {{-4,4},{-4,4}}, AspectRatio -> 1]

Eigenvalues[ {{-.5,-1},{1,-1}} ]

sol = NDSolve[ {x'[t] == y[t], y'[t] == -4 x[t],
		x[0] == y[0] == 1}, {x,y}, {t,10} ];

Eigenvalues[ {{0,1},{-4,0}} ]

ParametricPlot[ Evaluate[ {x[t], y[t]} /. sol ],
		{t,0,10}, PlotRange -> {{-3,3},{-3,3}}, AspectRatio -> 1 ]

Eigenvalues[{{1,1},{0,1}}]

sol = NDSolve[ {x'[t] == x[t] + y[t], y'[t] == y[t],
		x[0] == .5, y[0] == 1}, {x,y}, {t,-10,1} ];

ParametricPlot[ Evaluate[ {x[t], y[t]} /. sol ],
		{t,-10,1}, PlotRange -> {{-5,5},{-5,5}}, AspectRatio -> 1 ]

(*  4  *)

f[x_,y_] := { (1 - x^2 - y^2) x + 4 y, -4 x + (1 - x^2 - y^2) y }

D[f[x,y][[2]], y]

a := {{D[f[x,y][[1]], x], D[f[x,y][[1]], y]},{D[f[x,y][[2]], x], D[f[x,y][[2]], y]}}

MatrixForm[a]

a/.{x -> 0, y -> 0}

sol = NDSolve[ {x'[t] == (1 - x[t]^2 - y[t]^2) x[t] + 4 y[t],
				y'[t] == -4 x[t] + (1 - x[t]^2 - y[t]^2) y[t],
		x[0] == 0, y[0] == .1}, {x,y}, {t,10} ];

SetOptions[ParametricPlot, Axes -> True,
							PlotRange -> {{-2,2},{-2,2}}, AspectRatio -> 1];

ParametricPlot[ Evaluate[ {x[t], y[t]} /. sol ],
		{t,0,10} ]

sol = NDSolve[ {x'[t] == (1 - x[t]^2 - y[t]^2) x[t] + 4 y[t],
				y'[t] == -4 x[t] + (1 - x[t]^2 - y[t]^2) y[t],
		x[0] == 0, y[0] == 10}, {x,y}, {t,10} ];

SetOptions[ParametricPlot, Axes -> True,
							PlotRange -> {{-2,2},{-2,2}}, AspectRatio -> 1];

(*  van der Polin systeemi   *) 
 (*  Ylimaarainen tehtava .  
          Variaatio edellisesta.  *) 
 (*  Katso analyysi Kreyszigista  *)

f[x_,y_] := {x - x^3 + y, -x}

a := {{D[f[x,y][[1]], x], D[f[x,y][[1]], y]},
				{D[f[x,y][[2]], x], D[f[x,y][[2]], y]}}

a/. {x -> 0,y -> 0}

Eigenvalues[%]

sol = NDSolve[ {x'[t] == x[t] - x[t]^3 + y[t], y'[t] == -x[t],
		x[0] == 0, y[0] == .1}, {x,y}, {t,50} ];

SetOptions[ParametricPlot, Axes -> True,
							PlotRange -> {{-2,2},{-2,2}}];

ParametricPlot[ Evaluate[ {x[t], y[t]} /. sol ],
		{t,0,50} ]

(*   5  *)

LaplaceTransform[ Exp, t, s]

LaplaceTransform[ Exp[ct],  t,  s]

LaplaceTransform[ Exp[c t],  t,  s]

LaplaceTransform[ t^m,  t,  s]

LaplaceTransform[ f'[t],  t,  s]