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!