Vous êtes sur la page 1sur 21

function [Ra] =RaicesBesselMatriz(N,M,epsi)

Ra=zeros(N,M);
for n=1:N
[R]=RaicesBessel(n,M,epsi);
Ra(n,:)=[R];
end
end
DETERMINAR O CONSTRUIR LAS FUNCIONES DE BESSEL
function [W] = felipe( f,p,N,L )
%Desarrolla la funcion f(x) en serie de Fourier Bessel a travs de p,
%cib B sumandos. La funcin est dada en 0,L.
x=[0:0.1:(2.*pi.*N+20)];
h=@(x) besselj(p,x);
h1=h(x); m=1;
M=length(x);
for n=1:M-1
if (h1(n).*h1(n+1)<0)
A(m)=[x(n)]; B(m)=[x(n+1)];
m=m+1;
end
end
R=length(A);
for n=1:R
iz=[A(n)]; de=[B(n)];
while (de-iz)>0.0000001
med=(iz+de)./2;
if h(iz).*h(med)<0
de=med;
else
iz=med;
end
end
raiz(n)=med;
end
for n=1:N
f1=@(x) x.*f(x).*besselj(p,raiz(n).*x./L);
c(n)=integral(f1,0,L);
c(n)=2.*c(n)./((L.*besselj(p+1,raiz(n))).^2);
end
W=@(x) 0.*x;
for n=1:N
W=@(x) W(x)+c(n).*besselj(p,raiz(n).*x./L);
End
OPCIONAL U=[0: 0.01:L];
F1=f(x); %f1=f(u)
W1=W(u);
Figure, plot (u,W1,r, hold on, grid on, plot (u,f1,b)
End
F=@(x) exp (sin(x));
L=10;p=4; N=15;

PARA CALCULAR LOS M SUMANDOS ORDEN P


function [u] = SerieFourierBessel(f,p,M,epsi)
[R]=BesselRaices(p,M,epsi);
for m=1:M
f1=@(x) x.*f(x).*besselj(p,R(m).*x);
C(m)=integral(f1,0,1);
C(m)=C(m).*2./(besselj(p+1,R(m)).^2);
end
u=@(x) 0.*x;
for m=1:M
u=@(x) u(x)+C(m).*besselj(p,R(m).*x);
end
x=[0:0.01:1];
fun1=f(x); u1=u(x);
figure(),plot(x,fun1,'r'),hold on,grid on, plot(x,u1,'b')
end
f=@(x) 1-x.^3; M=15; epsi=0.000001; p=5;
PARA ENCONTRAR LOS NUMEROUS M RAICES N NUMERO DE RAICES Y P
EL GRADO DE BESSEL
function [R]=BesselRaices(p,M,epsi)
x=[0:0.1:(pi.*M).*2];
L=length(x); r=0;
for l=1:L-1
if besselj(p,x(l)).*besselj(p,x(l+1))<0
r=r+1;
A(r)=[x(l)]; B(r)=[x(l+1)];
end
end
for m=1:M
iz=A(m); de=B(m);
while(de-iz)>epsi;
med=(de+iz)./2;
if besselj(p,iz).*besselj(p,med)<0
de=med;
else
iz=med;
end
end
R(m)=med;
end
end
p=pi; N=15; epsi==0.000001;
[R]=BesselRaices(p,M,epsi)
function [W,R] =BesselJuan(f,p,M,L,epsi)
[R]=BesselRaices(p,M,epsi);
for n=1:M
f1=@(x) x.*f(x).*besselj(p,R(n).*(x./L));
C(n)=integral(f1,0,L);

d=L.*besselj(p+1,R(n));
d=d.^2;
d=d./2;
C(n)=C(n)./d;
end
W=@(x) 0.*x;
for n=1:M
W=@(x) W(x)+C(n).*besselj(p,R(n).*(x./L));
end
u=[0:0.1:L];
W1=W(u);
f1=f(u);
figure(),plot(u,W1,'r'),hold on,grid on,plot(u,f1,'b');
end
F=@(X) exp(sin(cos(x))); L=15; M=15; p=5; epsi=0.00001;
[W,R] =BesselJuan(f,p,M,L,epsi)
function [u] =OndaHomogenea(f,g,a,L,N)
for n=1:N
f1=@(x) f(x).*sin(n.*pi.*x./L);
A(n)=integral(f1,0,L).*2./L;
g1=@(x) g(x).*sin(n.*pi.*x./L);
B(n)=2.*integral(g1,0,L)./(n.*pi.*a);
end
u=@(x,t) 0.*x+0.*t;
for n=1:N
u=@(x,t) u(x,t)+(A(n).*cos(a.*n.*pi.*t./L)
+B(n).*sin(a.*n.*pi.*t./L)).*sin(n.*pi.*x./L);
end
x=[0:0.1:L]; t=[0:1:1000];
M=length(t);
for m=1:M
u1=u(x,t(m));
plot(x,u1,'r','LineWidth',5), hold on, grid on, hold off,axis([0 L -1 1])
pause(0.1)
end
end

function [u,A0,A,C] = FourierBessel2d(f,L,N,M,epsi)


[R]=RaicesBessel(0,M,epsi);
[Ra]=RaicesBesselMatriz(N,M,epsi);
A0=zeros(1,M); A=zeros(N,M); C=zeros(N,M);
for m=1:M
f1=@(fi,r) r.*f(r,fi).*besselj(0,R(m).*r./L);
d=(L.*besselj(1,R(m))).^2;

d=d.*pi./2;
A0(m)=integral2(f1,-pi,pi,0,L);
A0(m)=A0(m)./d;
end
for n=1:N
for m=1:M
fcos=@(fi,r) r.*f(fi,r).*besselj(n,Ra(n,m).*r./L).*cos(n.*fi);
fsin=@(fi,r) r.*f(fi,r).*besselj(n,Ra(n,m).*r./L).*sin(n.*fi);
A(n,m)=integral2(fcos,-pi,pi,0,L);
C(n,m)=integral2(fsin,-pi,pi,0,L);
d=(L.*besselj(n+1,Ra(n,m))).^2;
d=d.*pi./2;
A(n,m)=A(n,m)./d; C(n,m)=C(n,m)./d;
end
end
u=@(fi,r) 0.*r+fi.*0;
for m=1:M
u=@(fi,r) u(fi,r)+A0(m).*besselj(0,R(m).*r./L);
end
u=@(fi,r) 2.*u(fi,r);
for n=1:N
for m=1:M
u=@(fi,r) u(fi,r)+A(n,m).*besselj(n,Ra(n,m).*r./L).*cos(n.*fi);
u=@(fi,r) u(fi,r)+C(n,m).*besselj(n,Ra(n,m).*r./L).*sin(n.*fi);
end
end
S=[0:0.1:L]; Fi=[0:0.1:2.*pi];
[Fi,S]=meshgrid(Fi,S);
[Fi,S]=pol2cart(Fi,S);
u1=u(Fi,S);
figure(),surf(Fi,S,u1),hold on,grid on
end

function [w] =VibracionTamborCircular(f,g,a,L,N,M,epsi)


[R]=RaicesBessel(0,M,epsi);
[Ra]=RaicesBesselMatriz(N,M,epsi);
[u,A0,A,C]=FourierBessel2d(f,L,N,M,epsi);
w=@(fi,r,t) r.*0+fi.*0+t.*0;
for m=1:M
w=@(fi,r,t) w(fi,r,t)+A0(m).*cos(a.*R(m).*t./L).*besselj(0,R(m).*r./L);
end
w=@(r,fi,t) w(r,fi,t).*2;
for n=1:N

for m=1:M
w=@(fi,r,t) w(r,fi,t)
+A(n,m).*cos(a.*Ra(n,m).*t./L).*besselj(n,Ra(n,m).*r./L).*cos(fi.*n);
w=@(fi,r,t) w(r,fi,t)
+C(n,m).*cos(a.*Ra(n,m).*t./L).*besselj(n,Ra(n,m).*r./L).*sin(fi.*n);
end
end
s=[0:0.1:L]; Fi=[0:0.01:2.*pi];
[Fi,s]=meshgrid(Fi,s);
[Fi,s]=pol2cart(Fi,s);
t=[0:1:300]; T=length(t);
for n=1:T
w1=w(Fi,s,t(n));
surf(Fi,s,w1);hold on, grid on,axis([-2.*pi,2.*pi,-2.*L,2.*L,-1,1]),view(3),;
pause(0.5)
hold off;
end
end
function [u]=TamborCircular2(f,a,L,N,M,epsi)
[R]=RaicesBessel(0,M,epsi);
[Ra]=RaicesBesselMatriz(N,M,epsi);
A0=zeros(1,M); B0=zeros(1,M); A=zeros(N,M); B=zeros(N,M);
C=zeros(N,M); D=zeros(N,M);
for m=1:M
f1=@(fi,r) r.*f(fi,r).*besselj(0,R(m).*r./L);
A0(m)=integral2(f1,-pi,pi,0,L);
d=pi.*(L.*besselj(1,R(m))).^2;
A0(m)=A0(m)./d;
end
for n=1:N
for m=1:M
f1=@(fi,r) r.*f(fi,r).*besselj(n,Ra(n,m).*r./L).*cos(n.*fi);
f2=@(fi,r) r.*f(fi,r).*besselj(n,Ra(n,m).*r./L).*sin(n.*fi);
A(n,m)=integral2(f1,-pi,pi,0,L);
C(n,m)=integral2(f2,-pi,pi,0,L);
d=pi.*(L.*besselj(n+1,Ra(n,m))).^2;
A(n,m)=A(n,m).*2./d; C(n,m)=C(n,m).*2./d;
end
end
u=@(fi,r,t) fi.*0+r.*0+t.*0;
for m=1:M
u=@(fi,r,t) u(fi,r,t)+ (A0(m).*cos(a.*R(m).*t./L)
+B0(m).*sin(a.*R(m).*t./L)).*besselj(0,R(m).*r./L);
end
for n=1:N
for m=1:M
u=@(fi,r,t) u(fi,r,t)+(A(n,m).*cos(a.*Ra(n,m).*t./L)
+B(n,m).*sin(a.*Ra(n,m).*t./L)).*besselj(n,Ra(n,m).*r./L).*cos(n.*fi);
u=@(fi,r,t) u(fi,r,t)+(C(n,m).*cos(a.*Ra(n,m).*t./L)
+D(n,m).*sin(a.*Ra(n,m).*t./L)).*besselj(n,Ra(n,m).*r./L).*sin(n.*fi);

end
end
t=[0:1:200]; fi=[0:0.1:(2.*pi)]; r=[0:0.05:L];
[fi,r]=meshgrid(fi,r);
[fi,r]=pol2cart(fi,r);
S=length(t);
figure(),hold on,grid on
for s=1:S
u1=u(fi,r,t(s));
surf(fi,r,u1), view(-37.5,30);axis([-pi pi -L L -0.3 0.3]);
pause(0.01);
hold off
end
end
function [u] =TamborSinfi(f,g,a,L,N,epsi)
[R]=RaicesBessel(0,N,epsi);
A=zeros(N,1); B=zeros(N,1);
for n=1:N
f1=@(r) r.*f(r).*besselj(0,R(n).*r./L);
f2=@(r) r.*g(r).*besselj(0,R(n).*r./L);
A(n)=integral(f1,0,L);
B(n)=integral(f2,0,L);
d=(L.*besselj(1,R(n))).^2;
d1=d.*a.*R(n);
A(n)=A(n).*2./d;
B(n)=B(n).*2.*L./d1;
end
u=@(fi,r,t) r.*0+0.*t+0.*fi;
for n=1:N
u=@(fi,r,t) u(fi,r,t)+(A(n).*cos(a.*R(n).*t./L)
+B(n).*sin(a.*R(n).*t./L)).*besselj(0,R(n).*r./L);
end
u=@(fi,r,t)+u(fi,r,t)+0.*sin(fi);
r=[0:0.01:L]; fi=[-pi:0.1:pi+1]; t=[0:1:1000];
[fi,r]=meshgrid(fi,r);
[fi,r]=pol2cart(fi,r);
figure();
M=length(t);
for m=1:M
u1=u(fi,r,t(m));
surf(fi,r,u1), hold on, grid on;axis([-pi pi -L L -0.3 0.3]),view(-30,37.5);
pause(0.01);
hold off;
end
end
function [u]=TamborCircular(f,g,a,L,N,M,epsi)
[R]=RaicesBessel(0,M,epsi);
[Ra]=RaicesBesselMatriz(N,M,epsi);
A0=zeros(1,M); B0=zeros(1,M); A=zeros(N,M); B=zeros(N,M);

C=zeros(N,M); D=zeros(N,M);
for m=1:M
f1=@(fi,r) r.*f(fi,r).*besselj(0,R(m).*r./L);
g1=@(fi,r) r.*g(fi,r).*besselj(0,R(m).*r./L);
A0(m)=integral2(f1,-pi,pi,0,L);
B0(m)=integral2(g1,-pi,pi,0,L);
d=pi.*(L.*besselj(1,R(m))).^2;
d1=d.*a.*R(m)./L;
A0(m)=A0(m)./d; B0(m)=B0(m)./d1;
end
for n=1:N
for m=1:M
f1=@(fi,r) r.*f(fi,r).*besselj(n,Ra(n,m).*r./L).*cos(n.*fi);
f2=@(fi,r) r.*f(fi,r).*besselj(n,Ra(n,m).*r./L).*sin(n.*fi);
g1=@(fi,r) r.*g(fi,r).*besselj(n,Ra(n,m).*r./L).*cos(n.*fi);
g2=@(fi,r) r.*g(fi,r).*besselj(n,Ra(n,m).*r./L).*sin(n.*fi);
A(n,m)=integral2(f1,-pi,pi,0,L);
C(n,m)=integral2(f2,-pi,pi,0,L);
B(n,m)=integral2(g1,-pi,pi,0,L);
D(n,m)=integral2(g2,-pi,pi,0,L);
d=pi.*(L.*besselj(n+1,Ra(n,m))).^2;
d1=d.*a.*Ra(n,m);
A(n,m)=A(n,m).*2./d; C(n,m)=C(n,m).*2./d;
B(n,m)=B(n,m).*2.*L./d1; D(n,m)=D(n,m).*2.*L./d1;
end
end
u=@(fi,r,t) fi.*0+r.*0+t.*0;
for m=1:M
u=@(fi,r,t) u(fi,r,t)+ (A0(m).*cos(a.*R(m).*t./L)
+B0(m).*sin(a.*R(m).*t./L)).*besselj(0,R(m).*r./L);
end
for n=1:N
for m=1:M
u=@(fi,r,t) u(fi,r,t)+(A(n,m).*cos(a.*Ra(n,m).*t./L)
+B(n,m).*sin(a.*Ra(n,m).*t./L)).*besselj(n,Ra(n,m).*r./L).*cos(n.*fi);
u=@(fi,r,t) u(fi,r,t)+(C(n,m).*cos(a.*Ra(n,m).*t./L)
+D(n,m).*sin(a.*Ra(n,m).*t./L)).*besselj(n,Ra(n,m).*r./L).*sin(n.*fi);
end
end
t=[0:1:1000]; fi=[0:0.01:(2.*pi)]; r=[0:0.1:L]; lf=length(fi); lr=length(r);
k=lf.*lr;
[fi,r]=meshgrid(fi,r);
[fi,r]=pol2cart(fi,r);
S=length(t);
figure(),hold on,grid on
for s=1:S
u1=u(fi,r,t(s));
surf(fi,r,u1), view(0,90);axis([-2.*pi 2.*pi -2.*L 2.*L -2 2]);
pause(0.01);
hold off;
end

end
function [z] =Laplasian1D(x,y,a,b,h)
M=length(y);
F=diff(y,2);
z=zeros(M,1);
z(1)=[a];
z(M)=[b];
d=ones(M-2,1);
d0=-2.*d;
B=[d d0 d];
b=[-1 0 1];
C=spdiags(B,b,M-2,M-2);
D=(h.^2).*diff(y,2);
D(1)=[D(1)-z(1)];
D(M-2)=[D(M-2)-z(M)];
H=inv(C)*D';
for m=2:M-1
z(m)=[H(m-1)];
end
figure(),plot(x,y,'r'),hold on, grid on,plot(x,z,'b');
end

function [C] = LaplasianMatriz(A,h)


[M,N]=size(A);
C=zeros(M-2,N-2);
for m=2:M-1
for n=2:N-1
C(m-1,n-1)=[A(m+1,n)-4.*A(m,n)+A(m-1,n)+A(m,n+1)+A(m,n-1)]./(h.^2);
end
end
end
METODO DE DIFERENCIAS FINITAS PARA DARNOS LA COORDENADA DE
LOS VALORES LA MATRIZ
function [u] = JRubio(F,G,a,b,c,d,h)
x=[1:1:6];
y=[1:1:5];
[x,y]=meshgrid(x,y);
F1=F(x,y); G1=G(x,y);
u=zeros(5,6);
u(1,:)=[G1(1,:)]; u(5,:)=[G1(5,:)];
u(:,1)=[G1(:,1)]; u(:,6)=[G1(:,6)];
d=ones(12,1);
d0=-4.*d;
dp=ones(3,1);

dm=[dp;0]; dM=[0;dp];
dm1=dm; dM1=dM;
for m=2:3
dm1=[dm1;dm];
dM1=[dM;dM1];
end
B=[d dm1 do dM1 d];
b=[-4 -1 0 1 4];
C=spdiags(B,b,12,12);
D=zeros(12,1);
D(1)=[(h.^2).*F1(2,2)-u(1,2)-u(2,1)];
D(2)=[(h.^2).*F1(2,3)-u(1,3)];
D(3)=[(h.^2).*F1(2,4)-u(1,4)];
D(4)=[(h.^2).*F1(2,5)-u(1,5)-u(2,6)];
D(5)=[(h.^2).*F1(3,2)-u(3,1)];
D(6)=[(h.^2).*F1(3,3)];
D(7)=[(h.^2).*F1(3,4)];
D(8)=[(h.^2).*F1(3,5)-u(3,6)];
D(9)=[(h.^2).*F1(4,2)-u(5,2)-u(4,1)];
D(10)=[(h.^2).*F1(4,3)-u(5,3)];
D(11)=[(h.^2).*F1(4,4)-u(5,4)];
D(12)=[(h.^2).*F1(4,5)-u(5,5)-u(4,6)];
Z=inv(C).*D;
end

function [u] =Laplace(F,G,a,b,c,d,h)


x=[a:h:b]; y=[c:h:d];
M=length(y); N=length(x);
[x,y]=meshgrid(x,y); F1=F(x,y);
G1=G(x,y);
u=zeros(M,N);
u(1,:)=[G1(1,:)]; u(M,:)=[G1(M,:)];
u(:,1)=[G1(:,1)]; u(:,N)=[G1(:,N)];
s=(M-2).*(N-2);
d=ones(s,1);
d0=-4.*d;
dp=ones(N-3,1); dm=[dp;0]; dm1=dm;
dP=ones(N-3,1); dM=[0;dP]; dM1=dM;
for m=1:M-3
dm1=[dm1;dm];
dM1=[dM1;dM];
end
B=[d dm1 d0 dM1 d];
b=[-(N-2) -1 0 1 (N-2)];
C=spdiags(B,b,s,s);
D=zeros(s,1);
r=1;
D((N-2).*(r-1)+1)=[(h.^2).*F1(2,2)-u(2,1)-u(1,2)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(2,N-1)-u(2,N)-u(1,N-1)];
for n=2:N-3

D((N-2).*(r-1)+n)=[(h.^2).*F1(2,n+1)-u(1,n+1)];
end
r=(M-2);
D((N-2).*(r-1)+1)=[(h.^2).*F1(M-1,2)-u(M-1,1)-u(M,2)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(M-1,N-1)-u(M-1,N)-u(M,N-1)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(M-1,n+1)-u(M,n+1)];
end
for r=2:M-3
D((N-2).*(r-1)+1)=[(h.^2).*F1(r+1,2)-u(r+1,1)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(r+1,N-1)-u(r+1,N)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(r+1,n+1)];
end
end
Z=inv(C)*D;
for r=1:M-2
for n=1:N-2
u(r+1,n+1)=[Z((N-2).*(r-1)+n)];
end
end
surf(x,y,u);
end
function [LA] =Laplasiano2D(A)
[M,N]=size(A);
LA=zeros(M-2,N-2);
for m=2:M-1
for n=2:N-1
LA(m-1,n-1)=[A(m-1,n)-4.*A(m,n)+A(m+1,n)+A(m,n-1)+A(m,n+1)];
end
end
end
function [u] = EquacionLaplaceMatriz(A,Bi,Bs,Li,Ld)
[M,N]=size(A);
[LA]=Laplasiano2D(A);
F1=zeros(M,N);
F1(2:M-1,2:N-1)=[LA];
u=zeros(M,N); h=1;
u(1,:)=[Bi]; u(M,:)=[Bs]; u(:,1)=[Li]; u(:,N)=[Ld];
s=(M-2).*(N-2);
d=ones(s,1);
d0=-4.*d;
dp=ones(N-3,1); dm=[dp;0]; dm1=dm;
dP=ones(N-3,1); dM=[0;dP]; dM1=dM;
for m=1:M-3
dm1=[dm1;dm];
dM1=[dM1;dM];
end
B=[d dm1 d0 dM1 d];

b=[-(N-2) -1 0 1 (N-2)];
C=spdiags(B,b,s,s);
D=zeros(s,1);
r=1;
D((N-2).*(r-1)+1)=[(h.^2).*F1(2,2)-u(2,1)-u(1,2)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(2,N-1)-u(2,N)-u(1,N-1)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(2,n+1)-u(1,n+1)];
end
r=(M-2);
D((N-2).*(r-1)+1)=[(h.^2).*F1(M-1,2)-u(M-1,1)-u(M,2)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(M-1,N-1)-u(M-1,N)-u(M,N-1)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(M-1,n+1)-u(M,n+1)];
end
for r=2:M-3
D((N-2).*(r-1)+1)=[(h.^2).*F1(r+1,2)-u(r+1,1)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(r+1,N-1)-u(r+1,N)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(r+1,n+1)];
end
end
Z=inv(C)*D;
for r=1:M-2
for n=1:N-2
u(r+1,n+1)=[Z((N-2).*(r-1)+n)];
end
end
end
function [u] =PoissonEcuacion(F,G,a,b,c,d,h)
x=[a:h:b]; y=[c:h:d]; N=length(x); M=length(y);
[x,y]=meshgrid(x,y);
F1=F(x,y); G1=G(x,y);
u=zeros(M,N);
u(1,:)=[G1(1,:)]; u(M,:)=[G1(M,:)];
u(:,1)=[G1(:,1)]; u(:,N)=[G1(:,N)];
s=(M-2).*(N-2);
d=ones(s,1);
d0=-4.*d;
dp=ones(N-3,1); dm=[dp;0]; dM=[0;dp];
dm1=dm; dM1=dM;
for m=3:M-1
dm1=[dm1;dm]; dM1=[dM;dM1];
end
B=[d dm1 d0 dM1 d];
b=[-(N-2) -1 0 1 (N-2)];
C=spdiags(B,b,s,s);
D=zeros(s,1);
D(1)=[(h.^2).*F1(2,2)-u(1,2)-u(2,1)];
D(N-2)=[(h.^2).*F1(2,N-1)-u(1,N-1)-u(2,N)];

for n=2:N-3
D(n)=[(h.^2).*F1(2,n+1)-u(1,n+1)];
end
D((N-2).*(M-3)+1)=[(h.^2).*F1(M-1,2)-u(M,2)-u(M-1,1)];
D((N-2).*(M-3)+N-2)=[(h.^2).*F1(M-1,N-1)-u(M,N-1)-u(M-1,N)];
for n=2:N-3
D((N-2).*(M-3)+n)=[(h.^2).*F1(M-1,n+1)-u(M,n+1)];
end
for m=2:M-3
D((N-2).*(m-1)+1)=[(h.^2).*F1(m+1,2)-u(m+1,1)];
D((N-2).*(m-1)+N-2)=[(h.^2).*F1(m+1,N-1)-u(m+1,N)];
for n=2:N-3
D((N-2).*(m-1)+n)=[(h.^2).*F1(m+1,n+1)];
end
end
Z=inv(C)*D;
for m=1:M-2
for n=1:N-2
u(m+1,n+1)=[Z((N-2).*(m-1)+n)];
end
end
figure()
surf(x,y,u);
end
function [r] =RaicesBessel(p,N)
x=[0:0.1:(2.*pi.*N+20)];
M=length(x);
f=@(x) besselj(p,x);
f1=f(x); m=1;
for n=1:M-1
if (f1(n).*f1(n+1)<0)
A(m)=[x(n)]; B(m)=[x(n+1)];
m=m+1;
end
end
L=length(A);
for l=1:L
iz=A(l); de=B(l);
while (de-iz)>0.0000001
med=(de+iz)./2;
if (f(iz).*f(med)<0)==1
de=med;
else
iz=med;
end
end
r(l)=med;
end
end

function [u] =TamborOscilante(f,g,a,L,N)


[r]=RaicesBessel(0,N);
r0=r;
for m=1:N
f1=@(r,fi) r.*f(r,fi).*besselj(0,r(m).*r./L);
g1=@(r,fi) r.*g(r,fi).*besselj(0,r(m).*r./L)
A0(m)=integral2(f1,0,L,-pi,pi);
A0(m)=A0(m)./(pi.*(L.*besselj(1,r(m)).^2));
B0(m)=integral2(g1,0,L,-pi,pi);
B0(m)=B0(m)./((a.*pi.*L.*r(m)).*(besselj(1,r(m)).^2));
end
for n=1:N
[r]=RaicesBessel(n,N)
r=r(1:N);
s(n,:)=[r];
end
for n=1:N
for m=1:N
h=@(r,fi) r.*f(r,fi).*cos(n.*fi).*besselj(n,s(n,m).*r./L);
A(n,m)=integral2(h,0,L,-pi,pi);
A(n,m)=2.*A(n,m)./(pi.*(L.*besselj(n+1,r(n,m))).^2);
q=@(r,fi) r.*f(r,fi).*sin(n.*fi).*besselj(n,s(n,m).*r./L);
C(n,m)=integral2(q,0,L,-pi,pi);
C(n,m)=2.*C(n,m)./(pi.*(L.*besselj(n+1,r(n,m))).^2);
d=@(r,fi) r.*g(r,fi).*cos(n.*fi).*besselj(n,s(n,m).*r./L);
B(n,m)=integral2(d,0,L,-pi,pi);
B(n,m)=2.*B(n,m)./(pi.*(L.*besselj(n+1,r(n,m))).^2);
B(n,m)=B(n,m).*a./s(n,m);
e=@(r,fi) r.*g(r,fi).*sin(n.*fi).*besselj(n,s(n,m).*r./L);
D(n,m)=integral2(d,0,L,-pi,pi);
D(n,m)=2.*D(n,m)./(pi.*(L.*besselj(n+1,r(n,m)).^2));
D(n,m)=D(n,m).*a./s(n,m);
end
end
u=@(r,fi,t) r.*0+fi.*0+t.*0;
for m=1:N
u=@(r,fi,t) u(r,fi,t)+(A0(m).*cos(a.*r0(m).*t./L)
+B0(m).*sin(a.*r0(m).*t./L)).*besselj(0,r0(m).*r./L);
end
for n=1:N
for m=1:N
u=@(r,fi,t)+(A(n,m).*cos(a.*s(n,m).*t./L)
+B(n,m).*sin(a.*s(n,m).*t./L)).*besselj(n,s(n,m).*r./L).*cos(n.*fi);
u=@(r,fi,t)+(C(n,m).*cos(a.*s(n,m).*t./L)
+D(n,m).*sin(a.*s(n,m).*t./L)).*besselj(n,s(n,m).*r./L).*sin(n.*fi);
end
end
r=[0:0.1:L];
fi=[0:0.1:2.*pi];
t=[0:0.1:10];
[r,fi]=meshgrid(r,fi);

[r,fi]=cartopol(r,fi);
T=length(t);
for n=1:T
u1=u(r,fi,t(n));
figure();surf(r,fi,u1),hold on,grid on,hold off
pause(0.5)
end
end
function [u]=OndaDifFinita(f,g,L,a,h,T)
x=[0:h:L]; N=length(x);
k=h./(2.*a);
t=[0:k:T]; M=length(t);
u=zeros(M,N);
f1=f(x); g1=g(x);
u(:,1)=[0]; u(:,N)=[0];
u(1,:)=[f1(:)];
for n=2:N-1
u(2,n)=u(1,n)+k.*g1(n);
end
for m=2:M-1
for n=2:N-1
u(m+1,n)=[2.*u(m,n)-u(m-1,n)+(u(m,n+1)-2.*u(m,n)+u(m,n-1))./4];
end
end
figure();
for m=1:M
plot(x,u(m,:),'r','LineWidth',3),hold on,grid on;
pause(0.1);
hold off
end
end
function [u] = ExplicitaHiperbolica(f,g,a,L,h,T)
x=[0:h:L]; k=h./(2.*a); N=length(x);
t=[0:k:T]; M=length(t);
u=zeros(M,N); f1=f(x), g1=g(x);
u(1,:)=[f1(:)]; u(:,1)=[0]; u(:,N)=[0];
for n=2:N-1
u(2,n)=u(1,n)+k.*g1(n);
end
for m=2:M
for n=2:N-1
u(m+1,n)=[2.*u(m,n)-u(m-1,n)+(u(m,n+1)-2.*u(m,n)+u(m,n-1))./4];
end
end
figure(), hold on, grid on
for m=1:M
plot(x,u(m,:));
pause(0.1);
hold off

end
end

function [U] =Hiperbolica2DDifF(F,G,a,L,D,h,T)


x=[0:h:L]; N=length(x);
y=[0:h:D]; M=length(y);
k=h./(2.*a); t=[0:k:T]; O=length(t);
[x,y]=meshgrid(x,y);
F1=F(x,y); G1=G(x,y);
U=zeros(M,N,O);
U(1,:,:)=[0]; U(M,:,:)=[0];
U(:,1,:)=[0]; U(:,N,:)=[0];
for m=2:M-1
for n=2:N-1
U(m,n,1)=[F1(m,n)];
end
end
for m=2:M-1
for n=2:N-1
U(m,n,2)=U(m,n,1)+k.*G1(m,n);
end
end
for o=2:O-1;
for m=2:M-1
for n=2:N-1
U(m,n,o+1)=[2.*U(m,n,o)-U(m,n,o-1)+(U(m+1,n,o)-2.*U(m,n,o)+U(m1,n,o))./2+(U(m,n+1,o)-2.*U(m,n,o)+U(m,n-1,o))./2];
end
end
end
figure();
for o=1:O
surf(x,y,U(:,:,o)), hold on,grid on,axis([0 L 0 D -2 2]);
pause(0.01);
hold off
end
end
Poisson
function [C] = LaplasianMatriz(A,h)
[M,N]=size(A);
C=zeros(M-2,N-2);
for m=2:M-1
for n=2:N-1
C(m-1,n-1)=[A(m+1,n)-4.*A(m,n)+A(m-1,n)+A(m,n+1)+A(m,n-1)]./(h.^2);
end
end
end

function [u] =Laplace(F,G,a,b,c,d,h)


x=[a:h:b]; y=[c:h:d];
M=length(y); N=length(x);
[x,y]=meshgrid(x,y); F1=F(x,y);
G1=G(x,y);
u=zeros(M,N);
u(1,:)=[G1(1,:)]; u(M,:)=[G1(M,:)];
u(:,1)=[G1(:,1)]; u(:,N)=[G1(:,N)];
s=(M-2).*(N-2);
d=ones(s,1);
d0=-4.*d;
dp=ones(N-3,1); dm=[dp;0]; dm1=dm;
dP=ones(N-3,1); dM=[0;dP]; dM1=dM;
for m=1:M-3
dm1=[dm1;dm];
dM1=[dM1;dM];
end
B=[d dm1 d0 dM1 d];
b=[-(N-2) -1 0 1 (N-2)];
C=spdiags(B,b,s,s);
D=zeros(s,1);
r=1;
D((N-2).*(r-1)+1)=[(h.^2).*F1(2,2)-u(2,1)-u(1,2)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(2,N-1)-u(2,N)-u(1,N-1)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(2,n+1)-u(1,n+1)];
end
r=(M-2);
D((N-2).*(r-1)+1)=[(h.^2).*F1(M-1,2)-u(M-1,1)-u(M,2)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(M-1,N-1)-u(M-1,N)-u(M,N-1)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(M-1,n+1)-u(M,n+1)];
end
for r=2:M-3
D((N-2).*(r-1)+1)=[(h.^2).*F1(r+1,2)-u(r+1,1)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(r+1,N-1)-u(r+1,N)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(r+1,n+1)];
end
end
Z=inv(C)*D;
for r=1:M-2
for n=1:N-2
u(r+1,n+1)=[Z((N-2).*(r-1)+n)];
end
end
surf(x,y,u);
end

function [LA] =Laplasiano2D(A)


[M,N]=size(A);
LA=zeros(M-2,N-2);
for m=2:M-1
for n=2:N-1
LA(m-1,n-1)=[A(m-1,n)-4.*A(m,n)+A(m+1,n)+A(m,n-1)+A(m,n+1)];
end
end
end
function [u] = EquacionLaplaceMatriz(A,Bi,Bs,Li,Ld)
[LA]=Laplasiano2D(A);
F1=zeros(M,N);
F1(2:M-1,2:N-1)=[LA];
u=zeros(M,N); h=1;
u(1,:)=[Bi]; u(M,:)=[Bs]; u(:,1)=[Li]; u(:,N)=[Ld];
s=(M-2).*(N-2);
d=ones(s,1);
d0=-4.*d;
dp=ones(N-3,1); dm=[dp;0]; dm1=dm;
dP=ones(N-3,1); dM=[0;dP]; dM1=dM;
for m=1:M-3
dm1=[dm1;dm];
dM1=[dM1;dM];
end
B=[d dm1 d0 dM1 d];
b=[-(N-2) -1 0 1 (N-2)];
C=spdiags(B,b,s,s);
D=zeros(s,1);
r=1;
D((N-2).*(r-1)+1)=[(h.^2).*F1(2,2)-u(2,1)-u(1,2)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(2,N-1)-u(2,N)-u(1,N-1)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(2,n+1)-u(1,n+1)];
end
r=(M-2);
D((N-2).*(r-1)+1)=[(h.^2).*F1(M-1,2)-u(M-1,1)-u(M,2)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(M-1,N-1)-u(M-1,N)-u(M,N-1)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(M-1,n+1)-u(M,n+1)];
end
for r=2:M-3
D((N-2).*(r-1)+1)=[(h.^2).*F1(r+1,2)-u(r+1,1)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(r+1,N-1)-u(r+1,N)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(r+1,n+1)];
end
end
Z=inv(C)*D;
for r=1:M-2
for n=1:N-2

u(r+1,n+1)=[Z((N-2).*(r-1)+n)];
end
end
end
function [Ab] =Bordada(A,r)
[M,N]=size(A);
Ab=ones(M,N);
p=1./r; a=[p:p:1];
for n=1:r
Ab(n,n:N-(n-1))=[a(n)];
Ab(M-(n-1),n:N-(n-1))=[a(n)];
Ab(n:M-(n-1),n)=[a(n)];
Ab(n:M-(n-1),N-(n-1))=[a(n)];
end
end
function [u] = Fotomontaje(A,B,r,Bi,Bs,Li,Ld)
[La]=Laplasiano2D(A); [Lb]=Laplasiano2D(B);
[Lab]=Bordada(La,r); [Lbb]=Bordada(Lb,r);
[P,Q]=size(Lab);
C=ones(P,Q); D=C-Lab;
Af=La.*Lab+Lb.*D;
[M,N]=size(A);
F1=zeros(M,N);
F1(2:M-1,2:N-1)=[Af];
u=zeros(M,N); h=1;
u(1,:)=[Bi]; u(M,:)=[Bs]; u(:,1)=[Li]; u(:,N)=[Ld];
s=(M-2).*(N-2);
d=ones(s,1);
d0=-4.*d;
dp=ones(N-3,1); dm=[dp;0]; dm1=dm;
dP=ones(N-3,1); dM=[0;dP]; dM1=dM;
for m=1:M-3
dm1=[dm1;dm];
dM1=[dM1;dM];
end
B=[d dm1 d0 dM1 d];
b=[-(N-2) -1 0 1 (N-2)];
C=spdiags(B,b,s,s);
D=zeros(s,1);
r=1;
D((N-2).*(r-1)+1)=[(h.^2).*F1(2,2)-u(2,1)-u(1,2)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(2,N-1)-u(2,N)-u(1,N-1)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(2,n+1)-u(1,n+1)];
end
r=(M-2);
D((N-2).*(r-1)+1)=[(h.^2).*F1(M-1,2)-u(M-1,1)-u(M,2)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(M-1,N-1)-u(M-1,N)-u(M,N-1)];
for n=2:N-3

D((N-2).*(r-1)+n)=[(h.^2).*F1(M-1,n+1)-u(M,n+1)];
end
for r=2:M-3
D((N-2).*(r-1)+1)=[(h.^2).*F1(r+1,2)-u(r+1,1)];
D((N-2).*(r-1)+(N-2))=[(h.^2).*F1(r+1,N-1)-u(r+1,N)];
for n=2:N-3
D((N-2).*(r-1)+n)=[(h.^2).*F1(r+1,n+1)];
end
end
Z=inv(C)*D;
for r=1:M-2
for n=1:N-2
u(r+1,n+1)=[Z((N-2).*(r-1)+n)];
end
end
end
function [u1] = EcuacionCalor(f,g,s,a,l,h,T)
x=[0:h:l]; N=length(x);
k=(h./(a).^2)./4;
t=[0:k:T]; M=length(t);
f1=f(x);
g1=g(t); s1=s(t);
u1=zeros(M,N);
u1(1,:)=[f1(:)];
u1(:,1)=[g1(:)];
u1(:,N)=[s1(:)];
for m=1:M-1
for n=2:N-1
u1(m+1)=[u1(m,n)./2+(u1(m,n+1)+u1(m,n-1))./4];
end
end
figure();
A=max(max(u1)); C=min(min(u1));
for m=1:M
B=zeros(10,N);
for r=1:10
B(r,:)=[u1(m,:)];
end
imshow(B,[C A]), colormap(winter), hold on, grid on
pause (0.1);
hold off
end
end
a=10; L=20; h=0,5; T=50;
f=@(x) (x.*(L-x)).^2;
g=@(t) 0.*t;
s=@(t) 0.*t;
[u1] = EcuacionCalor(f,g,s,a,l,h,T)
function [u] = membranadiferencias(f,g,A,B,C,D,a,h,i,T)

poisson

x=[A:h,B];
M=length(x);
y=[C:i:D];
N=length(y);
k=(h+i)./(2.*a);
t=[0:k:T];
L=length(t);
[x,y]=meshgrid(x,y);
F1=f(x,y);
G1=g(x,y);
u=Zeros(M,N,L);
u(1,:,:)=[0];
u(M,:,:)=[0];
u(:,1,:)=[0];
u(:,N,:)=[0];
u(:,:,1)=[F1(:,:)];
for m=2:M-1
for n=2:N-1
u(m,n,2)=u(m,n,1)+k.*G1(m,n);
end
end
for l=2:L-1
for m=2:M-1
for n=2:N-1
u(m,n,l+1)=2.*u(m,n,l)-u(m,n,l-1)+[[(u(m,n+1,l)-2.*u(m,n,l)+u(m,n1,l)).*i.^2]+[(u(m+1,n,l)-2.*u(m,n,l)+u(m-1,n,l)).*h.^2]]./4;
end
end
end
figure()
for l=1:L
surf(x,y,u(:,:,l)),hold on, grid on, pause(0.2),hold off
end
end

Realizar la funcin Serie de Fourier Bessel en funcin de un rango de


(0,L)
function [W,R] = BessejKevin(f,p,M,L,epsi)
[R]=BesselRaices(p,M,epsi);
for n=1:M
f1=@(x) x.*f(x).*besselj(p,R(n).*(x./L));
C(n)=integral(f1,0,L);
d=L.*besselj(p+1,R(n));
d=d.^2;
d=d./2;
C(n)=C(n)./d;
end

W=@(x) 0.*x;
for n=1:M
W=@(x) W(x)+C(n).*besselj(p,R(n).*(x./L));
end
u=[0:0.1:L];
W1=W(u);
f1=f(u);
figure(),plot(u,W1,'r'), hold on, grid on, plot(u,f1,'b');
end

Vous aimerez peut-être aussi