---
# System prepended metadata

title: Laboratorium 6 - Kamil Breguła

---

Laboratorium 6 - Kamil Breguła
=====

```matlab
cla;
clf;
h = 0.01;

x = [0:h:5];

fn = @(x) 2 .* 2 .* sin(x) + cos(2 .* x);

syms f(a)
f(a) = 2 * 2 * sin(a) + cos(2 * a);
dx_fn = diff(f, a);

r_fn = fn(x);
r_dx_fn = dx_fn(x);

% przednia
r_fn_1 = []
for i = 1:length(x)-1
    r = (r_fn(i+1) - r_fn(i)) ./ h;
    r_fn_1 = [r_fn_1 r];
end
r_fn_1 = [r_fn_1 dx_fn(x(length(x)))];

% tylnia
r_fn_2 = [dx_fn(x(1))];
for i = 2:length(x)
    r = (r_fn(i) - r_fn(i-1)) ./ h;
    r_fn_2 = [r_fn_2 r];
end

% centralna
r_fn_3 = [dx_fn(x(1))]
for i = 2:length(x)-1
    r = (r_fn(i+1) - r_fn(i-1)) ./ (2 .* h);
    r_fn_3 = [r_fn_3 r];
end
r_fn_3 = [r_fn_3 dx_fn(x(length(x)))];


hold on;

plot(x, r_fn_1)
plot(x, r_fn_2)
plot(x, r_fn_3)
legend('przednia', 'tylnia', 'centralna' )

hold off;
```

```matlab
cla;
clf;

vy = [0 1 2 3 4 5 6 7 8 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 9 8 7 6 5 4 3 2 1 0]

x = linspace(1, length(vy)*10, length(vy));
h = 10;
T = (1:1:length(vy))*10

r_fn = [0]
for i = 2:length(T)-1
    r = (vy(i + 1) - vy(i - 1)) ./ (2 .* h);
    r_fn = [r_fn r];
end

r_fn = [r_fn 0];
hold on;

plot(x, vy)
plot(x, r_fn)
legend('Predkosc', 'Przyspieszenie')

hold off;
```

![](https://i.imgur.com/IoLkxJX.png)
![](https://i.imgur.com/I0KCK9y.png)
