【问题标题】:Fourier series, can i get matlab to print the answer from each of theses loop?傅里叶级数,我可以让 matlab 从每个循环中打印答案吗?
【发布时间】:2016-06-25 08:33:14
【问题描述】:

Matlab,我可以让 matlab 在 3 个单独的行上打印每个循环的答案吗? 我一直让它正确地绘制图形,但它似乎只打印最后一个 fprintf 还是一起打印 3 个总数? 提前致谢 P.S 很抱歉这个问题,因为我知道这是一个非常简单的问题,但我对 matlab 很陌生!

clc;

a= input('\n\nEnter a value for a: ');
b= input('\n\nEnter a value for b: ');
L= input('\n\nEnter a value for L: ');

a0 = (a+b)/2; %average value of the function over one complete cycle

t = 0:0.1:6*L;

fprintf('ft = %f',a0)
f=a0;



for k=1:2:20; %loop 10 times to give first 10 terms of the series

bk = ((b-a)*2)/(k*pi); %value for bk
f=f+bk*sin(k*pi*t/L);

fprintf(' + %fsin%ft',bk,(k*pi/L))

end
subplot(2,3,1);
plot(t,f,'g');

title('Fourier Series');

ylabel('Amplitude');
xlabel('Time');
grid on;


for k=1:2:50; %loop 25 times to give first 25 terms of the series

bk = ((b-a)*2)/(k*pi); %value for bk
f=f+bk*sin(k*pi*t/L);

%fprintf(' + %fsin%ft',bk,(k*pi/L))

end
subplot(2,3,2);
plot(t,f, 'r');
title('Fourier Series');

ylabel('Amplitude');
xlabel('Time');
grid on;


for k=1:2:100; %loop 50 times to give first 50 terms of the series

bk = ((b-a)*2)/(k*pi); %value for bk
f=f+bk*sin(k*pi*t/L);

%fprintf(' + %fsin%ft',bk,(k*pi/L))

end
subplot(2,3,4);
plot(t,f, 'b')
title('Fourier Series');

ylabel('Amplitude');
xlabel('Time');
grid on;

【问题讨论】:

    标签: matlab fft


    【解决方案1】:

    \n 添加到 fprintf 语句中,如下所示:

    fprintf(' + %f sin %ft\n',bk,(k*pi/L))

    【讨论】:

      猜你喜欢
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      • 1970-01-01
      • 1970-01-01
      • 2016-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多