Please help me find my mistakes here in coding of MATLAB

clc;
close all;
for i=1:200
t(i)=(i-1)/40;
p(i)=10*cos(2*pi*t(i)/5-0.5)+7.0*cos(4*pi*t(i)/5-0.2)+2.0*cos(6.0*pi*t(i)/5-0.1)
end
figure(1)
plot(t,p)
xlabel(' t');
ylabel('p(t)');
title(' Time series plot');
figure(2)
a=fft(p);
plot(abs(a));
title(' amplitude')
for i=1:200
b(i)=real(a(i));
c(i)=imag(a(i));
d(i)=atan(-c(i)/b(i));
e(i)=sqrt(b(i)^2+c(i)^2);
end
print('Real part','\n',b);
print('Imaginary part','\n',c);
print('Phase angle','\n',d);
print('Amplitude','\n',e);
figure(3);
plot(d);
title(' Phase')
figure(4);
plot(t,b,t,c,'*');
title(' Real and Imaginary part(*)')

What is this code supposed to do? How is it not working?

Welcome there,

I would read up on the documentation for print, because it should not be used like that. I think you want fprintf.

Otherwise, as Jeremy said, we do not know what you expect the results to look like.

This code is for the plotting of responses to periodic loadings. It plots the first graph (i.e time vs loading) but the second graph when Fourier Transformation is used, doesn’t plot.

I like to get a graph that looks like these.

I’d print the output of the fft. Is it correct?

Yes. It is correct, taken from book.

Have you corrected the use of print?

It would be helpful if you provided the error messages so we don’t have to guess, but I do agree that the print function is wrong.

I’m not sure what you mean by

You checked the output of the fft function against a book?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.