# Praktická cvičení z Numerické matematiky

## Počáteční (Cauchyova) úloha pro ODR - 7. týden

• Rovnice y' = -4.2 y, y(0) = 1, Explicitní Eulerova metoda
• ``` y = 1;
n = 4;
dt = 1 / n;
for i = 1:(2n), y(i+1) = y(i) + h * (-4.2 * y(i));, end
```
• Rovnice y' = -4.2 y, y(0) = 1, Implicitní Eulerova metoda
• ``` y = 1;
n = 4;
dt = 1 / n;
for i = 1:(2n), y(i+1) = y(i)/ (1  + h * 4.2);, end
```
• Graf řešení.
• ```  x = (0:(2n)) * dt;
plot(x, y);
```
• Rovnice X' = A X, X(0) = u, Explicitní Eulerova metoda
• ```A  = [ -0.2  10;  -10  -0.05];   X  = [  2 ; 0 ];
T  = 4;
n  = 800;
dt = T / n;
% postupne pro i = 1, 2, 3, ... opakujeme
i = 1;
k1 = A * X(:,i),
X(:,i+1) = X(:,i) + dt * k1;  end
```
• Graf řešení, fázová trajektorie
• ```tt = 0:dt:T;
plot(tt, X(1,:));

plot(X(1,:), X(2,:));
```
• Implicitní Eulerova metoda pro soustavu ODR (linearni)
• X ' = A X
```A  = [ -0.2  10;  -10  -0.05];   X  = [  2 ; 0 ];
T  = 4;
n  = 800;
dt = T / n; B = eye(size(A,1)) - dt * A;
i = 1;
% opakujeme
X(:,i+1) = B \ X(:,i); i = i +1;
```
• Collatzova metoda pro soustavu ODR
• X ' = A X
```A  = [ -0.2  10;  -10  -0.05];   X  = [  2 ; 0 ];
T  = 4;
n  = 800;
dt = T / n;
i = 1;
% Opakujeme
k1 = A * X(:,i);
Xpom = X(:,i) + dt * k1;
k2 = A * Xpom;
X(:,i+1) = X(:,i) + dt * k2;  end
```