intro.m 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. %% 1.
  2. % f(x,y,z) = sin((x*pi)/10)*sin((y*pi)/10)*abs(sin(t))
  3. % z= f(x, z, t_konst)
  4. x = 0:10;
  5. y = 0:10;
  6. %for i = t_konst
  7. % hold on;
  8. % for j = x
  9. % for k = y
  10. % plot(i, sin((j*pi)/10)*sin((k*pi)/10)*abs(sin(i)), '*')
  11. % pause(.5)
  12. % end
  13. % end
  14. %end
  15. % t_konst
  16. t_konsts = 0:10;
  17. for i = t_konsts
  18. hold on;
  19. [X, Y] = meshgrid(x, y);
  20. mesh(X, Y, sin((X*pi)/10).*sin((Y*pi)/10).*abs(sin(i)));
  21. pause(5);
  22. end
  23. hold off;
  24. %% 2.
  25. % dx/dt = Ax + Bu
  26. % y = c' x
  27. % x(k+1) = x(k) + T_a * f(x(k), u(k))
  28. % x(k) approx x(k * T_a)
  29. % t = k * T_a
  30. m = 1; % kg
  31. c = 1; % Ns/m
  32. k = 2; % N/m
  33. s_0 = 0; % m
  34. v_0 = 0; % m/s
  35. Ta = .1; % s
  36. integration_space = 0:Ta:20;
  37. x = zeros(size(integration_space) + 1);
  38. u = x;
  39. %for i = integration_space
  40. % x(k+1) = x(k) + T_a * f(x(k), u(k));
  41. % y = s = [0 1]' [x_1 x_2]
  42. %end
  43. %% 3.
  44. m = 1; % kg
  45. c = 1; % Ns/m
  46. k = 2; % N/m
  47. Ta = .1; % s
  48. % state space representation
  49. A = [0 1; -k/m -c/m];
  50. B = [0;1/m];
  51. C = [1,0];
  52. D = 0;
  53. % construct system
  54. sys = ss(A,B,C,D);
  55. % discretize system
  56. discrete_sys = c2d(sys,Ta,'zoh');
  57. % plot step response
  58. step(discrete_sys)