Code runs very slow
1 回表示 (過去 30 日間)
古いコメントを表示
clc;
close all;
clear all;
%Define domain
syms x
L = pi;
N = 1024;
dx = 2*L/(N-1);
%Define rectangular function
f = rectangularPulse(-1,1,x);
%Compute Fourier series
CC = jet(20);
F0 = sum(f.*ones(size(x)))*dx/pi;
fFS = F0/2;
for k = 1:20
A(k) = sum(f.*cos(pi*k*x/L))*dx/pi;
B(k) = sum(f.*sin(pi*k*x/L))*dx/pi;
fFS = fFS + 2*A(k)*cos(k*pi*x/L) - 2*B(k)*sin(k*pi*x/L);
fplot(x,fFS,'-','Color', CC(k,:),'LineWidth',2);
hold on;
end
Hi all, anyone helps me fix this code please, it runs so slow to see the plot
0 件のコメント
採用された回答
Walter Roberson
2022 年 3 月 4 日
L = pi;
N = 1024;
x = linspace(-5,5,N);
dx = 2*L/(N-1);
%Define rectangular function
f = rectangularPulse(-1,1,x);
%Compute Fourier series
CC = jet(20);
F0 = sum(f.*ones(size(x)))*dx/pi;
fFS = F0/2;
for k = 1:20
A = sum(f.*cos(pi*k*x/L))*dx/pi;
B = sum(f.*sin(pi*k*x/L))*dx/pi;
fFS = fFS + 2*A*cos(k*pi*x/L) - 2*B*sin(k*pi*x/L);
plot(x,fFS,'-','Color', CC(k,:),'LineWidth',2);
hold on;
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Mathematics and Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!