• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest May 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. close all; clear all;
2. TS_lab_04
3. function TS_lab_04
4. tspan1 =[0 0.25];
5. tspan2 =[0.251 0.50];
6. tspan3 =[0.501 0.75];
7. tspan4 =[0.751 1];
8. x0_1 =[1 0 0];
9. a1 =0.04; b1 =0.6; c1 = 0.2;
10. a2 =0.05; b2 = 0.35; c2 =0.37;
11. a3 = 0.13; b3 =0.0067; c3 =0.2;
12. a4 0.1; b4 =0.4; c4 = 0.3;
13. [ tsol , xsol ] = ode45 ( @ (t , x ) odefcn (t ,x , a1 , b1 , c1 ) , tspan1 , x0_1 );
14. x3 =1 - xsol (: ,1) - xsol (: ,2);
15. z1 =[0.25 ,0.25];
16. z2 =[0.5 ,0.5];
17. z3 =[0.75 ,0.75];
18. y =[0 ,1];
19. figure (1); hold on ; grid on ;
20. plot ( tsol , xsol (: ,1) , ’r ’ , tsol , xsol (: ,2) , ’b ’ , tsol , x3 , ’g ’ );
21. title ( ’ Wykres ␣ x ( t ));
22. xlabel ( ’t ’ );
23. ylabel ( ’x ( t ));
24. % legend ( ’x1 ’ , ’x2 ’ , ’x3 ’);
25. x0_2 =[ xsol (end ,1) xsol (end ,2) x3 (end )];
26. [ tsol , xsol ] = ode45 ( @ (t , x ) odefcn (t ,x , a2 , b2 , c2 ) , tspan2 , x0_2 );
27. x3 =1 - xsol (: ,1) - xsol (: ,2);
28. plot ( tsol , xsol (: ,1) , ’r ’ , tsol , xsol (: ,2) , ’b ’ , tsol , x3 , ’g ’ );
29. x0_3 =[ xsol (end ,1) xsol (end ,2) x3 (end )];
30. [ tsol , xsol ] = ode45 ( @ (t , x ) odefcn (t ,x , a3 , b3 , c3 ) , tspan3 , x0_3 );
31. x3 =1 - xsol (: ,1) - xsol (: ,2);
32. plot ( tsol , xsol (: ,1) , ’r ’ , tsol , xsol (: ,2) , ’b ’ , tsol , x3 , ’g ’ );
33. x0_4 =[ xsol (end ,1) xsol (end ,2) x3 (end )];
34. [ tsol , xsol ] = ode45 ( @ (t , x ) odefcn (t ,x , a4 , b4 , c4 ) , tspan4 , x0_4 );
35. x3 =1 - xsol (: ,1) - xsol (: ,2);
36. plot ( tsol , xsol (: ,1) , ’r ’ , tsol , xsol (: ,2) , ’b ’ , tsol , x3 , ’g ’ );
37. plot ( z1 ,y , ’k - - ’ );
38. plot ( z2 ,y , ’k - - ’ );
39. plot ( z3 ,y , ’k - - ’ );
40. t1 =0:0.001:0.25;
41. t2 = t1 +0.25;
42. t3 = t2 +0.25;
43. t4 = t3 +0.25;
44. u1 = @ ( t ) min (max ( 0.31 , 0) , 1);
45. u2 = @ ( t ) min (max ( 0.32 , 0) , 1);
46. 4
47. u3 = @ ( t ) min (max ( 0.2 , 0) , 1);
48. u4 = @ ( t ) min (max ( 0.25, 0) , 1);
49. figure (2); hold on ; grid on ;
50. title ( ’ Wykres ␣ czterech ␣ funkcji ␣ u ( t ) ␣ zmiennych ␣ na ␣ p r z e d z i a a c h ’ );
51. xlabel ( ’t ’ );
52. ylabel ( ’u ( t ));
53. plot ( t1 , u1 ( t1 ));
54. plot ( t2 , u2 ( t2 ));
55. plot ( t3 , u3 ( t3 ));
56. plot ( t4 , u4 ( t4 ));
57. plot ( z1 ,y , ’k - - ’ );
58. plot ( z2 ,y , ’k - - ’ );
59. plot ( z3 ,y , ’k - - ’ );
60. end
61. function dxdt = odefcn (t ,x ,a ,b , c )
62. u = a * t * t + b * t + c ;
63. if u >1
64. u =1;
65. end
66. if u <0
67. u =0;
68. end
69. dxdt = zeros (3 ,1);
70. dxdt (1) = u *(10* x (2) - x (1));
71. dxdt (2) = u *( x (1) -10* x (2)) -(1 - u )* x (2);
72. 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