I'm very new to MATLAB and I'm having alot of trouble debugging this. I need to write an M file that will accept a vector T, and a scalar C (zeta) and return a vector y whose value is defined as,
y=e^(-CT)*(2Ccos(Wd*T)+(We/Wd)*sin(Wd*T))
where Wd=sqrt(1-C^2) and We=1-2C^2 for C=[0,0.2,0.3,0.4,0.5] over the interval T=[0,4pi].
I keep getting the three same messages depending on the changes I make. Either, Matrix dimensions must agree, or error using ".*" or error using "*". Here is my code,
C=[0 0.2 0.3 0.4 0.5];T=0:0.01:4*pi;y=exp((-C).*T)*((2*C*cos((sqrt(1-(C^2)).*T)))+(((1-2*(C^2))/(sqrt(1-(C^2))))*sin((sqrt(1-(C^2))).*T)));y=response(T,C(1));figure;plot(T,y,'b');hold ony=response(T,C(2));plot(T,y,'r');hold ony=response(T,C(3));plot(T,y,'k');hold ony=response(T,C(4));plot(T,y,'m');hold ony=response(T,C(5));plot(T,y,'--b');hold onI've had help with it but I'm still not able to get it to work. Like I said, I'm very new to this. I've spent hours trying to debug this myself but I just don't know what I'm doing well enough to find the problem.I can get the desired results from this code but I'm pretty sure that this is not the way they want it to be done, T = 0:0.01:4*pi;y=exp(T*(-0)).*((2*0*cos(T*(sqrt(1-(0^2)))))+(((1-2*(0^2))/(sqrt(1-(0^2)))).*sin(T*(sqrt(1-(0^2))))));plot (y);hold ony=exp(T*(-0.2)).*((2*0.2*cos(T*(sqrt(1-(0.2^2)))))+(((1-2*(0.2^2))/(sqrt(1-(0.2^2)))).*sin(T*(sqrt(1-(0.2^2))))));plot (y);hold ony=exp(T*(-0.3)).*((2*0.3*cos(T*(sqrt(1-(0.3^2)))))+(((1-2*(0.3^2))/(sqrt(1-(0.3^2)))).*sin(T*(sqrt(1-(0.3^2))))));plot (y);hold ony=exp(T*(-0.4)).*((2*0.4*cos(T*(sqrt(1-(0.4^2)))))+(((1-2*(0.4^2))/(sqrt(1-(0.4^2)))).*sin(T*(sqrt(1-(0.4^2))))));plot (y);hold ony=exp(T*(-0.5)).*((2*0.5*cos(T*(sqrt(1-(0.5^2)))))+(((1-2*(0.5^2))/(sqrt(1-(0.5^2)))).*sin(T*(sqrt(1-(0.5^2))))));plot (y);hold on grid on legend('C=0','C=0.2','C=0.3','C=0.4','C=0.5'); ylabel ('y axis') xlabel ('T axis') title ('Graph of y=e^-^C^T(2Ccos(w_dT)+(w_e/w_d)sin(w_dT))')
Best Answer