● Magnetske analogije fraktalnih bazena		   Web
 Mario Matijevic, FER

x(0 )= -0.95, y(0) = 0.09                                                        x(0) = -0.95, y(0) = 0.095                                                        x(0) = -0.95, y(0) = 0.1

● Vremenski odzivi i animacija njihala									        (1)

Vremenski odziv sustava

<< LinearAlgebra`MatrixManipulation`
<< Graphics`Animation`
Off[General::spell1];
Off[General::spell];
n = Input["Unesi broj magneta: "];
K = 0.5; 
R = 
        0.2;

d = 
      0.25;       
tmax = 
      30;     
x0 = 
      Input["* pocetni uvjet: x(0)= "];           
y0 = 
      Input["* pocetni uvjet: y(0)= "];  
ε = 0.05;

(*slijede analogije s fraktalnim bazenima*) 
f[z_] = z^n - 1;

    derivacija[z_] = f'[z];

    nule = NSolve[f[z] == 0, z];

    polovi = NSolve[derivacija[z] == 0, z];

    dim1 = Part[Dimensions[nule], 1];    

    dim2 = Part[Dimensions[polovi], 1];

(*k ⟶ 
          vektor nultocaka*) 
 (*p ⟶ 
          vektor polova*) 
lista1 = niz1 = k = tocke1 = 
              Range[dim1];   (*alokacija memorije*) 

    lista2 = niz2 = p = tocke2 = 
              Range[dim2];

\(For[i = 1, 
      i ≤ 
        dim1, \(i++\), 
	\(k[\([i]\)] = 
          nule[\([i, 1, 2]\)];\)]\)
\(For[i = 1, 
      i ≤ 
        dim2, \(i++\), 
	\(p[\([i]\)] = 
          polovi[\([i, 1, 2]\)];\)]\)

For[
      i = 1, i ≤ 
        dim1, i++, 
lista1[[i]] = {Re[k[[i]]], 
          Im[k[[i]]]}]

    For[i = 1, 
      i ≤ 
        dim2, i++, 
lista2[[i]] = {Re[p[[i]]], 
          Im[p[[i]]]}]

For[i = 1, 
        i ≤ dim1, i++, 
tocke1[[i]] = 
          Point[lista1[[i]]]] ;      
For[i = 1, 
        i ≤ dim2, i++, 
tocke2[[i]] = 
          Point[lista2[[i]]]] ;

(*trazimo rjesenje vezanog sustava gibanja za x i y koordinatu*) 
rjesenje = 
      NDSolve[{x''[t] + 
              R*x'[
                  t] - ((∑_(i = 1)^n)(( Re[k[[i]]] - x[t])/((((Sqrt[(((Re[k[[i]]] - x[t]))^2) + (((Im[k[[i]]] - y[t]))^2) + (d^2)])))^3))) + K*x[t] == 
            0, y''[t] + 
              R*y'[
                  t] - ((∑_(i = 1)^n)(( Im[k[[i]]] - y[t])/((((Sqrt[(((Re[k[[i]]] - x[t]))^2) + (((Im[k[[i]]] - y[t]))^2) + (d^2)])))^3))) + K*y[t] == 0, 
x[0] == x0, 
          y[0] == y0, x'[0] == 0, y'[0] == 0}, {x, 
          y}, {t, 0, tmax - 1}]

vektor = 
        Table[{x[t] /. rjesenje, y[t] /. rjesenje}, {t, 0, tmax - 1, 
            0.1}];

    dim = Part[Dimensions[vektor], 1];

data = animacija = 
          Range[dim];     
For[i = 1, 
      i ≤ dim, i++, 
{a = vektor[[i]]; 
        xkoord = Part[a, 1, 1]; ykoord = Part[a, 2, 1]; 
        data[[i]] = {xkoord, ykoord}}]

Print[""];
Print[
        StyleForm["Vremenski odziv sustava: ", FontSize -> 16, 
          FontWeight -> "Bold", FontFamily -> "Arial", 
          FontColor -> Hue[0.7]]];
Print[""];

xgibanje = 
          Plot[{x[t] /. rjesenje} ,  {t, 0, tmax - 1}, 
            PlotStyle -> Hue[0.7],  PlotRange -> All, 
            AxesLabel -> {"t(s)", "x(t)"}, 
            PlotPoints -> 300, DisplayFunction -> Identity];

ygibanje = 
          Plot[{y[t] /. rjesenje} ,  {t, 0, tmax - 1}, 
            PlotStyle -> Hue[0.7],  PlotRange -> All, 
            AxesLabel -> {"t(s)", "y(t)"},  
            PlotPoints -> 300, DisplayFunction -> Identity];

sustav = 
        GraphicsArray[{{xgibanje, ygibanje}}, 
          ImageSize -> 500];
Show[sustav,  Background -> GrayLevel[0.9]]

ListPlot[data,PlotJoined -> True,AspectRatio -> Automatic,AxesOrigin -> {0, 0},ImageSize -> 500,PlotStyle -> {Hue[0.7], PointSize[0.006]},Background -> GrayLevel[0.9],Frame -> False,PlotLabel -> 
          StyleForm["Polozaj njihala kao funkcija vremena", 
            FontSize -> 14, FontWeight -> "Bold", 
            FontFamily -> "Times"],PlotRange -> {{-2, 2}, {-2, 2}},Epilog->{{PointSize[0.015], Hue[0.1], tocke1},{Text[StyleForm["● ⟶ MAGNET",FontSize -> 12,FontWeight -> "Bold",FontFamily -> "Arial"],{-1.6, 1.8}]},{Text[StyleForm["- ⟶ NJIHALO",FontSize -> 12,FontWeight -> "Bold",FontFamily -> "Arial"],{-1.6, 1.65}]}}]

Animacija njihala

Print[""];
Print[
        StyleForm["Polozaj njihala u vremenu: ", FontSize -> 16, 
          FontWeight -> "Bold", FontFamily -> "Arial", 
          FontColor -> 
            Hue[0.7]]];
Print[""];
For[i = 1,i ≤ dim,i++,
animacija[[i]]=ListPlot[{data[[i]]},AspectRatio -> Automatic,AxesOrigin -> {0, 0},ImageSize -> 400,PlotStyle -> {Hue[0.7], PointSize[0.015]},Background -> GrayLevel[0.9],Frame -> False,DisplayFunction -> Identity,PlotLabel -> 
                StyleForm["polozaj u sekundi"⟶(i*0.1 - 
                        0.1), FontSize -> 14, 
                  FontWeight -> "Bold", 
                  FontFamily -> "Times"],PlotRange -> {{-2, 2}, {-2, 2}},Epilog->{{PointSize[0.015], Hue[0.1], tocke1},{Text[StyleForm["● ⟶ MAGNET",FontSize -> 12,FontWeight -> "Bold",FontFamily -> "Arial"],{-1.45, 1.8}]},{Text[StyleForm["● ⟶ NJIHALO",FontSize -> 12,FontWeight -> "Bold",FontFamily -> "Arial"],{-1.45, 1.65}]}}]]
ShowAnimation[animacija]

● Tranzijentni dijagram ravnine									        (2)

xgrid = 
        150;

    ygrid = 150;

    matrica = data = ZeroMatrix[xgrid, ygrid];

    sol = Range[xgrid*ygrid];

    xmax = 2;

    ymax = 2;

    xmin = -2;

    ymin = -2;

    dx = (xmax - xmin)/xgrid;

    dy = (ymax - ymin)/ygrid;

For[i = 1, 
        i ≤ xgrid, i++, 
For[j = 1, 
          j ≤ 
            ygrid, j++, {
x00 = xmin  +  (i*dx); 
            y00 = ymax - (j*dy); 
(sol = 
                NDSolve[{x''[t] + 
                        R*x'[
                            t] - (∑_(i = 1)^n)(( Re[k[[i]]] - x[t])/((((Sqrt[(((Re[k[[i]]] - x[t]))^2) + (((Im[k[[i]]] - y[t]))^2) + (d^2)])))^3)) + K*x[t] == 
                      0, y''[t] + 
                        R*y'[
                            t] - (∑_(i = 1)^n)(( Im[k[[i]]] - y[t])/((((Sqrt[(((Re[k[[i]]] - x[t]))^2) + (((Im[k[[i]]] - y[t]))^2) + (d^2)])))^3)) + K*y[t] == 0, 
x[0] == x00, 
                    y[0] == y00, x'[0] == 
                      0, y'[0] == 0}, {x, y}, {t, 0, tmax - 1}]); 
            matrica[[j, 
                  i]] = (x[tmax - 1] /. 
                    sol) + I*(y[tmax - 1] /. sol)}]] // 
      Timing

Dimensions[matrica]

(*transformacija konvergencijske matrice u boju*) 
For[i = 1, 
        i ≤ xgrid, i++, 
For[j = 1, 
          j ≤ 
            ygrid, j++, {
boja = 
              0.123; 
For[h = 1, 
              h ≤ dim1, h++, 
If[
                Abs[matrica[[j, i, 1]] - 
                      k[[h]]] < ε, (boja = 
                    h/dim1)]]; 
data[[j, i]] = 
              boja}
]] // Timing

r = 
      Part[Dimensions[data], 1];      
s = 
      Part[Dimensions[data], 2];      
nova = 
      ZeroMatrix[r, s];
For[i = 1, 
        i ≤ r, i++, 
nova[[r - i + 1]] = 
          data[[i]]];

    
\(tranzijent = 
      ListDensityPlot[nova, Mesh -> False, ImageSize -> 225, 
        ColorFunction -> Hue, 
        PlotLabel -> "tranzijentni proces", 
        FrameStyle -> Thickness[0.008], 
        FrameTicks -> {{{0, "-2"}, {xgrid/4, "-1"}, {xgrid/
                  2, "0"}, {3 
                   xgrid/4, "1"}, {xgrid, "2"}}, {{0, "-2"}, {ygrid/4, "-1"}, {ygrid/2, "0"}, {3 
                   ygrid/4, "1"}, {ygrid, "2"}}}]\)