12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- %% 1.
- % f(x,y,z) = sin((x*pi)/10)*sin((y*pi)/10)*abs(sin(t))
- % z= f(x, z, t_konst)
- x = 0:10;
- y = 0:10;
- %for i = t_konst
- % hold on;
- % for j = x
- % for k = y
- % plot(i, sin((j*pi)/10)*sin((k*pi)/10)*abs(sin(i)), '*')
- % pause(.5)
- % end
- % end
- %end
- % t_konst
- t_konsts = 0:10;
- for i = t_konsts
- hold on;
- [X, Y] = meshgrid(x, y);
- mesh(X, Y, sin((X*pi)/10).*sin((Y*pi)/10).*abs(sin(i)));
- pause(5);
- end
- hold off;
- %% 2.
- % dx/dt = Ax + Bu
- % y = c' x
- % x(k+1) = x(k) + T_a * f(x(k), u(k))
- % x(k) approx x(k * T_a)
- % t = k * T_a
- m = 1; % kg
- c = 1; % Ns/m
- k = 2; % N/m
- s_0 = 0; % m
- v_0 = 0; % m/s
- Ta = .1; % s
- integration_space = 0:Ta:20;
- x = zeros(size(integration_space) + 1);
- u = x;
- %for i = integration_space
- % x(k+1) = x(k) + T_a * f(x(k), u(k));
- % y = s = [0 1]' [x_1 x_2]
- %end
- %% 3.
- m = 1; % kg
- c = 1; % Ns/m
- k = 2; % N/m
- Ta = .1; % s
- % state space representation
- A = [0 1; -k/m -c/m];
- B = [0;1/m];
- C = [1,0];
- D = 0;
- % construct system
- sys = ss(A,B,C,D);
- % discretize system
- discrete_sys = c2d(sys,Ta,'zoh');
- % plot step response
- step(discrete_sys)
|