Untitled

                Never    
close all; clear all;
TS_lab_04
function TS_lab_04
tspan1 =[0 0.25];
tspan2 =[0.251 0.50];
tspan3 =[0.501 0.75];
tspan4 =[0.751 1];
x0_1 =[1 0 0];
a1 =0.04; b1 =0.6; c1 = 0.2;
a2 =0.05; b2 = 0.35; c2 =0.37;
a3 = 0.13; b3 =0.0067; c3 =0.2;
a4 0.1; b4 =0.4; c4 = 0.3;
[ tsol , xsol ] = ode45 ( @ (t , x ) odefcn (t ,x , a1 , b1 , c1 ) , tspan1 , x0_1 );
x3 =1 - xsol (: ,1) - xsol (: ,2);
z1 =[0.25 ,0.25];
z2 =[0.5 ,0.5];
z3 =[0.75 ,0.75];
y =[0 ,1];
figure (1); hold on ; grid on ;
plot ( tsol , xsol (: ,1) , ’r ’ , tsol , xsol (: ,2) , ’b ’ , tsol , x3 , ’g ’ );
title ( ’ Wykres ␣ x ( t ) ’ );
xlabel ( ’t ’ );
ylabel ( ’x ( t ) ’ );
% legend ( ’x1 ’ , ’x2 ’ , ’x3 ’);
x0_2 =[ xsol (end ,1) xsol (end ,2) x3 (end )];
[ tsol , xsol ] = ode45 ( @ (t , x ) odefcn (t ,x , a2 , b2 , c2 ) , tspan2 , x0_2 );
x3 =1 - xsol (: ,1) - xsol (: ,2);
plot ( tsol , xsol (: ,1) , ’r ’ , tsol , xsol (: ,2) , ’b ’ , tsol , x3 , ’g ’ );
x0_3 =[ xsol (end ,1) xsol (end ,2) x3 (end )];
[ tsol , xsol ] = ode45 ( @ (t , x ) odefcn (t ,x , a3 , b3 , c3 ) , tspan3 , x0_3 );
x3 =1 - xsol (: ,1) - xsol (: ,2);
plot ( tsol , xsol (: ,1) , ’r ’ , tsol , xsol (: ,2) , ’b ’ , tsol , x3 , ’g ’ );
x0_4 =[ xsol (end ,1) xsol (end ,2) x3 (end )];
[ tsol , xsol ] = ode45 ( @ (t , x ) odefcn (t ,x , a4 , b4 , c4 ) , tspan4 , x0_4 );
x3 =1 - xsol (: ,1) - xsol (: ,2);
plot ( tsol , xsol (: ,1) , ’r ’ , tsol , xsol (: ,2) , ’b ’ , tsol , x3 , ’g ’ );
plot ( z1 ,y , ’k - - ’ );
plot ( z2 ,y , ’k - - ’ );
plot ( z3 ,y , ’k - - ’ );
t1 =0:0.001:0.25;
t2 = t1 +0.25;
t3 = t2 +0.25;
t4 = t3 +0.25;
u1 = @ ( t ) min (max ( a1 .* t  + b1 , 0) , 1);
u2 = @ ( t ) min (max ( a2 .* t .* t + b2 .* t + c2 , 0) , 1);
4
u3 = @ ( t ) min (max ( a3 .* t .* t + b3 .* t + c3 , 0) , 1);
u4 = @ ( t ) min (max ( a4 .* t + b4, 0) , 1);
figure (2); hold on ; grid on ;
title ( ’ Wykres ␣ czterech ␣ funkcji ␣ u ( t ) ␣ zmiennych ␣ na ␣ p r z e d z i a a c h ’ );
xlabel ( ’t ’ );
ylabel ( ’u ( t ) ’ );
plot ( t1 , u1 ( t1 ));
plot ( t2 , u2 ( t2 ));
plot ( t3 , u3 ( t3 ));
plot ( t4 , u4 ( t4 ));
plot ( z1 ,y , ’k - - ’ );
plot ( z2 ,y , ’k - - ’ );
plot ( z3 ,y , ’k - - ’ );
end
function dxdt = odefcn (t ,x ,a ,b , c )
u = a * t * t + b * t + c ;
if u >1
u =1;
end
if u <0
u =0;
end
dxdt = zeros (3 ,1);
dxdt (1) = u *(10* x (2) - x (1));
dxdt (2) = u *( x (1) -10* x (2)) -(1 - u )* x (2);
end

Raw Text