1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| clear; clc; close all;
L=1;
n=40;
x=linspace(-L,L,n);
dx=x(2)-x(1);
%% Grafische Darstellung
f=@(x) 32*x.*(x.^2-1);
y=f(x);
subplot(3,2,1),plot (x,y,'r');
hold on;
title('f(x)');
%% symbolische Lösung
syms xx n pi
bn(n)=int((32*xx*(xx^2-1)*sin(n*pi*xx/L)), xx,-L,L); %symbolische Funktion
an(n)=int((32*xx*(xx^2-1)*cos(n*pi*xx/L)), xx,-L,L); %symbolische Funktion
bn(n)=simplify(bn(n));
pretty(bn(n)) ;
fft(xx)=0+0*xx;
for n=1:40
fft(xx)= fft(xx)+bn(n)*sin(pi*n*xx/L); %symbolische Funktion
end
y=@(x) double(fft(x));
subplot(3,2,2),plot(x,y(x),'b');
title('symbolische Lösung');
%% numerische Lösung
f=@(x) 32*x.*(x.^2-1);
An= zeros(n,1);
Bn= zeros(n,1);
for x=-L:L
for n=1:40 %integral
An(n)=(2\L)*integral(f(x)*cos(n*pi*x/L),-L,L);
% Bn(n)=(2.\L)*integral(f(x).*sin(n*pi*x/L),-L,L);
%ft=An(n)*cos(pi*n*x/L)+Bn(n)*sin(pi*n*x/L);
end
end
y3=@(x) double(An(n))
subplot(3,2,5),plot (x,y3,'b');
title('An'); |
Partager