









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This matlab script explores the phase portraits, eigenvectors, eigenvalues, and stability properties of a 2x2 matrix as the parameter u varies from -2 to 2. The script plots the representative trajectories, eigenvectors, and eigenvalues, and labels the plot with the trace and determinant of the matrix.
Typology: Assignments
1 / 16
This page cannot be seen from the preview
Don't miss anything!










Sarah Adelman MATH246 Extra Credit %Phase plane as u goes from -2 to 2 for u=-2:.1: A=[u+1, -u; u ,u-1]; pplane(A) hold on end function pplane(A)
% pplane.m Plots the eigenvectors, eigenvalues, and representative % phase portraits for % % d[x; y]/dt = A[x; y] % % for -1<x<1, -1<y<1. Called as % % pplane(A) % % where A is the 2x2 coefficient array. Calls lodesolver.m, % so be sure that function is in the current path
[U,S] = eig(A);
lam = diag(S);
if lam(1) == lam(2) % manually set u2 to be orthogonal to u U(:,2) = [-U(2,1); U(1,1)]; end
figure
if isreal(lam(1))
plot([-U(1,1) U(1,1)],[-U(2,1) U(2,1)],'--', ... [-U(1,2) U(1,2)],[-U(2,2) U(2,2)],'Linewidth',2) legend('u_1','u_2') else plot(0,0,'o','MarkerSize',12,'LineWidth',2) end xlabel('x'), ylabel('y') grid on trA = A(1,1)+A(2,2); detA = A(1,1)A(2,2) - A(1,2)A(2,1); title(['tr(A) = ',num2str(trA),' det(A) = ',num2str(detA)])
tmax = sqrt(abs(lam(1))^2+abs(lam(2))^2)/2; incr = 1/max(abs(lam))/20; t = [0:0.05:tmax]; hold on for i = 1: z0 = 2*rand(2,1)-[1;1]; z = lodesolver(A,t,z0);
plot(z(1,:),z(2,:),'r.-') end hold off
H = axes('position',[0.1 0.75 0.2 0.2]); plot(real(lam(1)),imag(lam(1)),'bX',real(lam(2)),imag(lam(2)),'go', ... 0,0,'.','LineWidth',2) ax = axis; xrng = ax(2)-ax(1); yrng = ax(4)-ax(3); hold on plot([ax(1)-0.05xrng ax(2)+0.05xrng],[0 0],'r', ... [0 0],[ax(3)-0.05yrng ax(4)+0.05yrng],'r') axis tight hold off
set(H,'YTick',[]),set(H,'XTick',[])
drawnow