0% found this document useful (0 votes)
62 views

% F Es Una Funcion en Formato at Respecto de T: Function

This document contains functions for calculating Fourier series representations of functions over different intervals. The functions take a function f as an input and calculate its Fourier coefficients to generate Fourier series approximations of f over various intervals and boundary conditions. The functions are used to plot the original function against the Fourier series approximations.

Uploaded by

Joyce Vera Ayala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

% F Es Una Funcion en Formato at Respecto de T: Function

This document contains functions for calculating Fourier series representations of functions over different intervals. The functions take a function f as an input and calculate its Fourier coefficients to generate Fourier series approximations of f over various intervals and boundary conditions. The functions are used to plot the original function against the Fourier series approximations.

Uploaded by

Joyce Vera Ayala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 7

function[s] = fouriergeneral (f,N,T)

% f es una funcion en formato @ respecto de t


x= @(t) t.*pi./T;
t=@ (x) T.*x ./pi;
g=@ (x) f(t(x));
[s]= Fourier(g,N);
w=@(t) s(x(t));

u=[-T:0.01:T];
F=f(u);
W1= w(u);
figure();
plot(u,F,'r'),hold on, grid on, plot(u,W1,'b');
end

function[w] = fourierasimetrico(f,A,B,N)
% furier con intervalos entre A y B
x= @(t) (t-(A+B)./2).*(2.*pi)./(B-A);
t=@ (x) x.*(B-A)./(2.*pi)+(A+B)./2;;
g=@ (x) f(t(x));
[s]= Fourier(g,N);
w=@(t) s(x(t));

u=[-A:0.01:B];
F=f(u);
W1= w(u);
figure();
plot(u,F,'b'),hold on, grid on, plot(u,W1,'r');
end

function[Sseno] = senofourier(f,T,N)
for n=1:N
f1= @(x) f( x).*sin(n.*pi.*x./T);
b(n)=2.*integral(f1,0,T)./T;
end
Sseno=@(x) 0.*x;
for n=1:N
Sseno=@(x) Sseno(x)+b(n).*sin(n.*x);
end
u=[-T:0.01:T]
F=f(u) ;
Ssen1=Sseno(u);
figure();
plot(u,F,'r'),hold on, grid on,plot(u,Ssen1,'b');
end
function[Scos,a] = cosenofourier(f,A,B,N)
T=abs(A)+abs(B);
a0= 2.*integral(f,A,B)./T;
for n=1:N
f1= @(x) f(x).*cos(n.*x);
a(n)= 2.*integral(f1,A,B)./T;
end
Scos=@(x) a0./2+ 0.*x;
for n=1:N
Scos=@(x) Scos(x)+a(n).*cos(n.*x);
end
u=[A:0.01:B];
F=f(u) ;
Scos1=Scos(u);
figure();
plot(u,F,'r'),hold on, grid on,plot(u,Scos1,'b');
end

function[u]=cuerdavibrantejoice(f,g,a,L,N)
for n=1:N
f1=@(x) f(x).*sin(n.*pi.*x./L);
D(n)=2.*integral(f1,0,L)./L;
g1=@(x) g(x).*sin(n.*pi.*x./L);
c=2.*integral(g1,0,L)./L;
E(n)=L.*c./(a.*n.*pi);
end
u=@(x,t)0.*x+0.*t;
for n=1:N
u=@(x,t) u(x,t)+(D(n).*cos(n.*a.*pi.*t./L)+
E(n).*sin(n.*a.*pi.*t./L)).*sin(n.*pi.*x./L);
end
v=[0:0.001:L];
t=[0:1:100];
T=length(t);
figure();
for m=1:T
u1=u(v,t(m));
plot(v,u1,'r','linewidth',3),hold on, grid on, axis([0 L -L L]);
pause (0.5);
hold off;
end
function [ u ] = calor1Dneumann(f, L, a , N)
%UNTITLED2
a0=2.*integral(f,0,L)./L;
for n=1:N
f1=@(x) f(x).*cos(n.*pi.*x./L);
B(n)=2.*integral(f1,0,L)./L;
end
U=@(x,t) a0./2 +0.*x+0.*t;
for n=1:N
U= @(x,t) U(x,t)+B(n).*exp((-
(a.*n.*pi./L).^2).*t).*cos(n.*pi.*x./L);
end
v=[0:0.1:L];
t=[0:0.5:100]; M=length(t);
figure();
for m=1:M
U1=U(v,t(m));
plot(v,U1,'r','LineWidth',3),hold on, grid on;
pause(0.1);
hold off;
end
function [U]=joiceeliptica(f,L,D,N)

for n=1:N
f1= @(x) f(x).*sin(n.*pi.*x./L);
Paque= 2.*integral(f1,0,L)./L;
A(n)= Paque./sinh(n.*pi.*D./L);
end
U=@(x,y) 0.*x+0.*y;
for n=1:N
U= @(x,y) U(x,y)+A(n).*sinh(n.*pi.*y./L).*sin(n.*pi.*x./L);
end
x=[0:0.1:L];
y=[0:0.5:D];
[X,Y]= meshgrid(x,y);
figure();
U1=U(X,Y);
mesh(x,y,U1), hold on , grid on
for n= 1:N
f1=@(x) f(x).* sin((2.*n-1).*pi.*x./(2.*L));
B(n)= 2.*integral(f1,0,L)./L;
end

U=@(x,t) x.*0+t.*0;
for n= 1:N
U=@(x,t) U(x,t)+B(n).*exp(-(((2.*n-1).*pi.*a./
(2.*L)).^2).*t).*sin((2.*n-1).*pi.*x./(2.*L));
end

v=[0:0.1:L];
t=[0:1:200]; M =length(t);
figure();
for m=1:M
U1=U(v,t(m));
plot(v,U1,'r'), hold on, grid on;
pause(0.5); hold on;
end
function [U] = joiceDirichletNeumannn(f,L,a,N)

for n= 1:N
f1=@(x) f(x).* sin((2.*n-1).*pi.*x./(2.*L));
B(n)= 2.*integral(f1,0,L)./L;
end

U=@(x,t) x.*0+t.*0;
for n= 1:N
U=@(x,t) U(x,t)+B(n).*exp(-(((2.*n-1).*pi.*a./
(2.*L)).^2).*t).*sin((2.*n-1).*pi.*x./(2.*L));
end

v=[0:0.1:L];
t=[0:1:200]; M =length(t);
figure();
for m=1:M
U1=U(v,t(m));
plot(v,U1,'r'), hold on, grid on;
pause(0.5); hold on;
end
function [Scos,Sgen] = PrimeraLeccion(f,A,B,N)
%F depende de t
x = @(t) (t-(A+B)./2).*(2.*pi./(B-A));
t = @(x) (B-A).*x./(2.*pi)+(A+B)./2;
g = @(x) f(t(x));
a0=integral(g,-pi,pi)./pi;
for n=1:N
g1=@(x) g(x).*cos(n.*x);
g2=@(x) g(x).*sin(n.*x);

a(n)=integral(g1,-pi,pi)./pi;
b(n)=integral(g2,-pi,pi)./pi;
end
S=@(x) a0./2+0.*x;
for n=1:N
S=@(x) S(x)+a(n).*cos(n.*x)+b(n).*sin(n.*x);
end

Sgen = @(t) (S(x(t)));

x = @(t) (A-t).*pi./(A-B);
t = @(x) A-((x.*(A-B))./(pi));
h = @(x) f(t(x));

for n=1:N
h2=@(x) h(x).*cos(n.*x);
a1(n)=2.*integral(h2,0,pi)./pi;
end
Ss=@(x) a0./2+0.*x;

for n=1:N
Ss=@(x) Ss(x)+a1(n).*cos(n.*x);

end

Scos=@(t) Ss(x(t));

u=[A:0.01:B];
F=f(u);
Sgen1=Sgen(u);
Scos1=Scos(u);
figure(),plot(u,F,'r', 'LineWidth',2),hold on, grid
on,plot(u,Sgen1,'g'), plot(u,Scos1,'b');
end

You might also like