• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Sep 19th, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. % i
2. clc;
3. clear;
4. tspan = [0,10];      % Visualise solution from 0 to 5 seconds
5. x0 = [1,1];             % Initial condition of 1
6.
7. L = 3;
8. kappa = 2;
9. rho = L + kappa/sqrt(2);
10. sigma = @(x,z) x^2 + 4*x - 0.5*z;
11. v = @(x,z) -rho*sign(sigma(x,z));
12. u = @(x,z) v(x,z) - 2*x^3 - 10*x^2 - 12*x + x*z + 2*z;
13.
14. [t,x] = ode45(@(t,x) f_1(x,t,u),tspan,x0);
15.
16. x_surface = linspace(0,2,10);
17. z_surface = 2*x_surface.^2 + 8*x_surface;
18.
19. sigma_val = zeros(length(x),1);
20. u_val = zeros(length(x),1);
21. for i = 1:length(x)
22.     sigma_val(i) = sigma(x(i,1),x(i,2));
23.     u_val(i) = u(x(i,1),x(i,2));
24. end
25.
26. % Visualise solutions
27. figure('Name','i_1','NumberTitle','off','Position', [100, 100, 700, 400]);
28. plot(x(:,1),x(:,2),'Linewidth',2);
29. hold on
30. plot(x_surface,z_surface,'Linewidth',2);
31. title('x(t), z(t) With sliding surface \sigma = 0');
32. xlabel('x(t)');
33. ylabel('z(t)');
34.
35. figure('Name','i_2','NumberTitle','off','Position', [100, 100, 700, 400]);
36. subplot(1,3,1);
37. plot(t,x(:,1),'Linewidth',2);
38. title('t, x(t)');
39. xlabel('Time (s)');
40. ylabel('x(t)');
41. xlim(tspan);
42.
43. subplot(1,3,2);
44. plot(t,x(:,2),'Linewidth',2);
45. title('t, z(t)');
46. xlabel('Time (s)');
47. ylabel('z(t)');
48. xlim(tspan);
49.
50. subplot(1,3,3);
51. plot(t,sigma_val,'Linewidth',2);
52. title('t, \sigma(t)');
53. xlabel('Time (s)');
54. ylabel('\sigma(t)');
55. xlim(tspan);
56.
57. figure('Name','i_3','NumberTitle','off','Position', [100, 100, 700, 400]);
58. plot(t,u_val,'Linewidth',2);
59. title('t, u_{sm}(t)');
60. xlabel('Time (s)');
61. ylabel('u_{sm}(t)');
62. xlim(tspan);
63.
64. %% ii
65. clear x z
66. epsilon = 0.1;
67. v = @(x,z) -rho*min(max((sigma(x,z)/epsilon),-1),1);
68. u = @(x,z) v(x,z) - 2*x^3 - 10*x^2 - 12*x + x*z + 2*z;
69. [t,x] = ode45(@(t,x) f_1(x,t,u),tspan,x0);
70. sigma_val = zeros(length(x),1);
71. u_val = zeros(length(x),1);
72. for i = 1:length(x)
73.     sigma_val(i) = sigma(x(i,1),x(i,2));
74.     u_val(i) = u(x(i,1),x(i,2));
75. end
76.
77. % Visualise solutions
78. figure('Name','ii_1','NumberTitle','off','Position', [100, 100, 700, 400]);
79. subplot(1,3,1);
80. plot(t,x(:,1),'Linewidth',2);
81. title('t, x(t)');
82. xlabel('Time (s)');
83. ylabel('x(t)');
84. xlim(tspan);
85.
86. subplot(1,3,2);
87. plot(t,x(:,2),'Linewidth',2);
88. title('t, z(t)');
89. xlabel('Time (s)');
90. ylabel('z(t)');
91. xlim(tspan);
92.
93. subplot(1,3,3);
94. plot(t,sigma_val,'Linewidth',2);
95. title('t, \sigma(t)');
96. xlabel('Time (s)');
97. ylabel('\sigma(t)');
98. xlim(tspan);
99.
100. figure('Name','ii_2','NumberTitle','off','Position', [100, 100, 700, 400]);
101. plot(t,u_val,'Linewidth',2);
102. title('t, u_\epsilon(t)');
103. xlabel('Time (s)');
104. ylabel('u_\epsilon(t)');
105. xlim(tspan);
106.
107. %%
108. function dX = f_1(x,t,u)
109. dx = x(1)^2 + 3*x(1) - 0.5*x(2);
110. dz = -2*u(x(1),x(2)) + cos(t) + 2*sin(3*x(1)*x(2));
111. dX = [dx;dz];
112. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?