Download - matlab solution

Transcript

Part I

(1)function dx = solvingfunction1(t,x,a,b)dx = zeros(2,1);dx(1) = x(2);dx(2) = b*cos(t) - a*x(2) + x(1);end

(2)clear allclc a = [=0.12,0,0.12];b = 0; hold on for j=1:length(a) figure(j) for i=-2:1:2 [t,x] = ode45(@(t,x)solvingfunction1(t,x,a(j),b),[0, 2*pi], [i, i]); plot(t,x) title(sprintf('a=%d, b=%d',a(j),b)) endend

Part II

(1)function dx = solvingfunction2(t,x,a,b)dx = zeros(2,1);dx(1) = x(2);dx(2) = (x(1)^2-b)*x(2) - a*x(1) + x(1)^3;end

(2)clear allclc a = 0:0.25:1.25;b = 1; hold on for j=1:length(a) figure(j) for i=-2:1:2 [t,x] = ode45(@(t,x)solvingfunction2(t,x,a(j),b),[0, 10], [i, i]); plot(t,x) title(sprintf('a=%d and b=%d',a(j),b)) endend

Part III

(1)function dXdt = solvingfunction3(t,x,a,b)X = x(1);y = x(2);dxdt = a*(X-1/3*X^3-y);dydt = -X + 1 + b;dXdt = [dxdt; dydt];end

(2)clear allclc a = [1,5,10];b = -0.001; hold on for j=1:length(a) figure(j) for i=-2:1:2 [t,x] = ode45(@(t,x)solvingfunction3(t,x,a(j),b),[0, 10], [i, i]); plot(t,x) title(sprintf('a=%d, b=%d',a(j),b)) endend


Top Related