• API
• FAQ
• Tools
• Archive
SHARE
TWEET

Untitled

a guest Sep 19th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. % PART i
2. clc;
3. clear;
4. tspan = [0,10];
5. x0 = [1,1];
6.
7. L = 3;
8. kappa = 2;
9. rho = L + kappa/sqrt(2);
10.
11. sigma = @(x,z) x^2 + 4*x - 0.5*z;
12. delta = @(x,z,t) cos(t) + 2*sin(3*x*z);
13. v = @(x,z) -rho*sign(sigma(x,z));
14. u = @(x,z) v(x,z) - 2*x^3 - 10*x^2 - 12*x + x*z + 2*z;
15.
16. [t,x] = ode45(@(t,x) f_1(x,t,u,delta),tspan,x0);
17.
18. x_surface = linspace(0,2,20);
19. z_surface = 2*x_surface.^2 + 8*x_surface;
20.
21. sigma_val = zeros(length(x),1);
22. u_val = zeros(length(x),1);
23. for i = 1:length(x)
24.     sigma_val(i) = sigma(x(i,1),x(i,2));
25.     u_val(i) = u(x(i,1),x(i,2));
26. end
27.
28. % Visualise solutions
29. figure('Name','i_1','NumberTitle','off','Position', [100, 100, 700, 400]);
30. plot(x(:,1),x(:,2),'Linewidth',2);
31. hold on
32. plot(x_surface,z_surface,'Linewidth',2);
33. title('x(t), z(t) With sliding surface \sigma = 0');
34. xlabel('x(t)');
35. ylabel('z(t)');
36.
37. figure('Name','i_2','NumberTitle','off','Position', [100, 100, 700, 400]);
38. subplot(2,1,1);
39. plot(t,x(:,1),t,x(:,2),t,sigma_val,'Linewidth',2);
40. title('t, (x(t), z(t), \sigma(t))');
41. xlabel('Time (s)');
42. ylabel('x(t), z(t), \sigma(t)');
43. legend('x(t)','z(t)','\sigma(t)');
44. xlim(tspan);
45.
46. subplot(2,1,2);
47. plot(t,u_val,'Linewidth',2);
48. title('t, u_{sm}(t)');
49. xlabel('Time (s)');
50. ylabel('u_{sm}(t)');
51. xlim(tspan);
52.
53. %% PART ii
54. clc;
55. clear;
56. tspan = [0,10];
57. x0 = [1,1];
58.
59. epsilon = 0.1;
60. L = 3;
61. kappa = 2;
62. rho = L + kappa/sqrt(2);
63.
64. sigma = @(x,z) x^2 + 4*x - 0.5*z;
65. delta = @(x,z,t) cos(t) + 2*sin(3*x*z);
66. v = @(x,z) -rho*min(max((sigma(x,z)/epsilon),-1),1);
67. u = @(x,z) v(x,z) - 2*x^3 - 10*x^2 - 12*x + x*z + 2*z;
68.
69. [t,x] = ode45(@(t,x) f_1(x,t,u,delta),tspan,x0);
70.
71. sigma_val = zeros(length(x),1);
72. u_val = zeros(length(x),1);
73. for i = 1:length(x)
74.     sigma_val(i) = sigma(x(i,1),x(i,2));
75.     u_val(i) = u(x(i,1),x(i,2));
76. end
77.
78. % Visualise solutions
79. figure('Name','ii','NumberTitle','off','Position', [100, 100, 700, 400]);
80. subplot(2,1,1);
81. plot(t,x(:,1),t,x(:,2),t,sigma_val,'Linewidth',2);
82. title('t, (x(t), z(t), \sigma(t))');
83. xlabel('Time (s)');
84. ylabel('x(t), z(t), \sigma(t)');
85. legend('x(t)','z(t)','\sigma(t)');
86. xlim(tspan);
87.
88. subplot(2,1,2);
89. plot(t,u_val,'Linewidth',2);
90. title('t, u_\epsilon(t)');
91. xlabel('Time (s)');
92. ylabel('u_\epsilon(t)');
93. xlim(tspan);
94.
95. %% PARTS iii and iv
96. clc;
97. clear;
98. tspan = [0,10];      % Visualise solution from 0 to 5 seconds
99. x0 = [1,1,0];             % Initial condition of 1
100.
101. L = 3;
102. kappa = 2;
103. tau = 1;
104. rho = L + kappa/sqrt(2);
105.
106. sigma = @(x,z) x^2 + 4*x - 0.5*z;
107. delta = @(x,z,t) cos(t) + 2*sin(3*x*z);
108. u = @(x,z,xi) - 2*x^3 - 10*x^2 - 12*x + x*z + 2*z - rho*xi;
109. [t,x] = ode45(@(t,x) f_2(x,t,tau,u,sigma,delta),tspan,x0);
110.
111. u_val = zeros(length(x),1);
112. delta_val = zeros(length(x),1);
113. for i = 1:length(x)
114.     u_val(i) = u(x(i,1),x(i,2),x(i,3));
115.     delta_val(i) = delta(x(i,1),x(i,2),t(i));
116. end
117.
118. delta_hat = rho*x(:,3);
119.
120. % Visualise solutions
121. figure('Name','iii','NumberTitle','off','Position', [100, 100, 700, 400]);
122. subplot(2,1,1);
123. plot(t,x(:,1),t,x(:,2),t,x(:,3),'Linewidth',2);
124. title('t, (x(t), z(t), \xi(t))');
125. xlabel('Time (s)');
126. ylabel('x(t), z(t), \xi(t)');
127. legend('x(t)','z(t)','\xi(t)');
128. xlim(tspan);
129.
130. subplot(2,1,2);
131. plot(t,u_val,'Linewidth',2);
132. title('t, u_{eq}(t)');
133. xlabel('Time (s)');
134. ylabel('u_{eq}(t)');
135. xlim(tspan);
136.
137. figure('Name','iv','NumberTitle','off','Position', [100, 100, 700, 400]);
138. plot(t,delta_val,t,delta_hat,'Linewidth',2);
139. title('Disturbance Estimation');
140. xlabel('Time (s)');
141. ylabel('Disturbances');
142. legend('\delta(t)','\delta_{hat}(t)');
143. xlim(tspan);
144.
145. %%
146. function dX = f_1(x,t,u,delta)
147. dx = x(1)^2 + 3*x(1) - 0.5*x(2);
148. dz = -2*u(x(1),x(2)) + delta(x(1),x(2),t);
149. dX = [dx;dz];
150. end
151.
152. %%
153. function dX = f_2(x,t,tau,u,sigma,delta)
154. dx = x(1)^2 + 3*x(1) - 0.5*x(2);
155. dz = -2*(u(x(1),x(2),x(3))) + delta(x(1),x(2),t);
156. dxi = (-1/tau)*x(3) + (1/tau)*sign(sigma(x(1),x(2)));
157. dX = [dx;dz;dxi];
158. 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.

Top