%% PROBLEM 6_2 ALL MATLAB function [t,xs]=P6_2(alpha,init,I1,I2) gm=.05;cm=1;gc=.1; A1=[-(gm+alpha*gc)/cm alpha*gc/cm]; A2=[gc/cm -(gm+gc)/cm]; A=[A1;A2]; F=[I1/cm;I2/cm]; ss=-inv(A)*F; ssv=[ss;[0;0]]; lam=eig(A) dt0=A*init+F; M=[1 1 0 0;0 0 1 1; lam.' 0 0; 0 0 lam.']; %% Want non conjugate transpose b=[init; dt0]; as=inv(M)*(b-ssv) t=[0:.1:200]; x=as(1)*exp(lam(1)*t)+as(2)*exp(lam(2)*t)+ss(1,1); y=as(3)*exp(lam(1)*t)+as(4)*exp(lam(2)*t)+ss(2,1); [t,xs]=ode45('P6_2fun',t,init,[],alpha,I1,I2); v1=xs(:,1); v2=xs(:,2); figure(1); clf;plot(t,x,t,y,t,v1,t, v2);xlabel('time (secs)'); title('Comparison of simulation and analytical solution'); mess='Hit return to continue.' pause;