clear; clf; %%%%%%%%%%%%% % problem 2 % %%%%%%%%%%%%% t = 0; tstop = pi; y0 = [1 2]; tspan = [t tstop]; [tt,yy] = ode45('func9',tspan,y0); % plot numerical solution figure(1); plot(tt,yy(:,1), 'ro'); hold on; plot(tt,yy(:,2), 'b*'); grid on; % exact solution n = 100; h = (tstop - t) / n; tr = t : h : tstop; x = exp(tr) .* ( cos(2*tr) + sin(2*tr)); y = exp(tr) .* (2*cos(2*tr) - 2* sin(2*tr)); plot(tr,x,'r'); plot(tr,y,'b'); legend('x_1 numerical','x_2 numerical','x_1 exact','x_2 exact','Location','Northwest'); xlabel('\it{t}'); ylabel('\it{x_1, x_2}'); %%%%%%%%%%%%% % problem 3 % %%%%%%%%%%%%% clear; t = 0; tstop = 2*pi; y0 = [0 1]; tspan = [t tstop]; [tt,yy] = ode45('func9b',tspan,y0); % plot numerical solution figure(2); plot(tt,yy(:,1), 'ro'); hold on; %plot(tt,yy(:,2), 'b*'); grid on; % exact solution n = 100; h = (tstop - t) / n; tr = t : h : tstop; u = sin(tr); v = cos(tr); plot(tr,u,'r'); %plot(tr,v,'b'); legend('u numerical','u exact','Location','southwest'); xlabel('\it{x}'); ylabel('\it{u}');