Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
1er parcial funciones
1. *function [ z ] = MetodoBiseccion( f,a,b,e )
%f es unafuncioncontinua
%a,bson numerosreales
%e esun error
while abs(b-a)>e
m=(b-a)./2;
if f(m).*f(a) >=0
a=m;
else
b=m;
end
end
z=(b-a)./2;
end
*function [a,b,n]=CambioSigno(f,A,B)
x=[A:0.1:B];
f1=f(x);
N=length(x);
n=0;
for m=1:N-1
if f1(m).*f1(m+1)<0
n=n+1;
a(n)=x(m);
b(n)=x(m+1);
%else
end
end
end
*function[R]= Todas Raices (f,A,B,e)
[a,b,n] = CambioSigno(f,A,B);
fors = 1:n
[R(s)] =Biseccion(f,a(s),b(s),e);
end
end
length(R)---># de Raices
OTRO METODO DE TODAS RAICES
function[ z ] = MetodoNewton( f,a,b,N,e)
h=0.000001;
df=@(x) (f(x+h)-f(x))./h;
p0=(a+b)./2;
i=1;
while i<=N
p = p0 - f(p0)./df(p0);
if abs(p-p0)<e
z=p;
break;
end
i=i+1;
p0=p;
end
%disp('El metodohaterminadosin exito');
end
function[ z ] = TodasRaices( f,a,b,e )
% f esla funcion
% a y b representanel intervalo
% e esel error o tolerancia
% z es unvector contodas lasraicesde f
x=[a-e:0.01:b+e];
g=f(x);
n=1;
for i=1:length(g)-1
if g(i)*g(i+1)<=0
c=x(i);
d=x(i+1);
[r]=MetodoNewton(f,c,d,e,200);
z(n)=r;
n=n+1;
end
end
end
*function [ z ] = MetodoPuntoFijo( f,a,b,N,e )
cont=1;
p=(a+b)./2;
while cont<=N
z=f(p);
if abs(p-z)<=e
break;
else
cont=cont+1;
p=z;
end
end
end
*function [p]= PuntoFijo(g,p0,e)
q=g(p0);
n=1;
while n<100
while (abs(q-q0)>e)
p0=q;
q=g(p0);
n=n+1;
end
p=q;
end
2. *function [D] = Matriz_Inversa(A)
[N,M]=size(A);
B=eye(N,M);
C=[A B];
for m=1:N-1
[a p]=max(abs(C(m:N,1:N)));
[b q]=max(a);
f=[p(q)+(m-1)];
col=[q];
Bo=[C(m,:)];C(m,:)=[C(f,:)];C(f,:)=Bo;
Re(m)=[col];
C(m,:)=C(m,:)./C(m,col);
for n=1:N
if m==n
else
C(n,:)=C(n,:)-C(n,col).*C(m,:);
end
end
end
[a p]=max(abs(C(N,1:N)));
Re(N)=[p];
C(N,:)=C(N,:)./C(N,p);
for n=1:N-1
C(n,:)=C(n,:)-C(n,p).*C(N,:);
end
for m=1:M
forn=1:N
if C(n,m)==1
Bo=[C(m,:)];C(m,:)=[C(n,:)];C(n,:)=[Bo];
end
end
end
D=[C(:,M+1:M+M)]
end
*function[z]=metodo_secante(f,a,b,e)
p=b-f(b).*((b-a)./f(b)-f(a));
while abs(f(b))<e
if f(p)*f(a)>0
a=x;
else
b=x;
end
p=b-f(b).*((b-a)./f(b)-f(a));
end
z=p;
end
GRAFICATIEMPO EN MATRIZ INVERSA
for n=1:100
A=10.*rand(50,50);
ya=tic;
[D]=Inversa(A);
T(n)=toc(ya);
ya2=tic;
U=inv(A);
T2(n)=toc(ya2);
end
figure(),plot(T,'r'),holdon,gridon,plot(T2,'b');
*function [D]=DetClase(A)
[N,N]=size(A);
D=1;
VM=zeros(N,1);
for n=1:N-1
[a,p]=max(abs(A(n:N,:)));
[b,q]=max(abs(a));
r=p(q)+n-1;
if r==n
D=D.*A(r,q);
else
D=-D.*A(r,q);
end
B=[A(r,:)];
A(r,:)=[A(n,:)];
A(n,:)=[B];
A(n,:)=A(n,:)./A(n,q);
VM(n)=[q];
for m=1:N
if m==n
else
A(m,:)=A(m,:)-A(m,q).*A(n,:);
end
end
end
[a,p]=max(abs(A(N,:)));
VM(N)=[p];
D=D.*A(N,p);
A(N,:)=A(N,:)./A(N,p);
for m=1:N-1
A(m,:)=A(m,:)-A(m,p).*A(N,:);
end
c=0;
for n=1:N-1;
for m=n:N
if VM(n)>VM(m);
c=c+1;
end
end
end
if rem(c,2)==0
else
D=-D;
end
GRAFICATIEMPO DETERMINANTE
for n=1:100
A=rand(50,50);
ya=tic;
[D]=DetClase(A);
T(n)=toc(ya);
ya2=tic;
U=det(A);
T2(n)=toc(ya2);
end
figure(),plot(T,'r'),holdon,gridon,plot(T2,'b');
3. *function [T] = Soluciones(Tiempo)Sistema(A,B)
[N,M]=size(A);
C=[A B];
(inicia=tic);
for m=1:N-1
[a p]=max(abs(C(m:N,1:N)));
[b q]=max(a);
f=[p(q)+(m-1)];
col=[q];
Bo=[C(m,:)];C(m,:)=[C(f,:)];C(f,:)=Bo;
Re(m)=[col];
C(m,:)=C(m,:)./C(m,col);
for n=1:N
if m==n
else
C(n,:)=C(n,:)-C(n,col).*C(m,:);
end
end
end
[a p]=max(abs(C(N,1:N)));
Re(N)=[p];
C(N,:)=C(N,:)./C(N,p);
for n=1:N-1
C(n,:)=C(n,:)-C(n,p).*C(N,:);
end
for m=1:N
T(Re(m))=[C(m,N+1)];
end
(x=toc(inicia))
end
InterpolacionLagrange
*function [z]= PivoteGauss(A,B)
[N,N]=size(A);
C=[A B];
for n=1:N
[a p]=max(abs(C(n:N,n)));
q=p+(n-1);
Bo=[C(n,:)];C(n,:)=[C(q,:)];C(q,:)=[Bo];
C(n,:)=C(n,:)./C(n,n);
for m=1:N
if m==n
else
C(m,:)=C(m,:)-C(m,n).*C(n,:);
end
end
end
z=[C(:,N+1)];
end
C=vander(x);
[z]=PivoteGauss(C,y');
f=@(x) 0.*x;
for n=1:8
f=@(x) f(x)+z(n).*(x.^(8-n));
end
u=[x(1):0.001:x(8)];
f1=f(u);
figure(),plot(u,f1,'r','LineWidth',2),holdon,gridon,
plot(x,y,'b')
InterpolacionPartida de hasta 5 datos
x=[-2-1 0 1 2];
y=[4 1 -1 2 -3];
Ci=vander(x);
A=Ci;B=y';
[z]=PivoteGauss(A,B);
p=@(u) z(1).*u.^4+z(2).*u.^3+z(3).*u.^2+z(4).*u+z(5);
x1=[x(1:3)];
x2=[x(3:5)];
y1=[y(1:3)];
y2=[y(3:5)];
C1=vander(x1);
C2=vander(x2);
[z1]=PivoteGauss(C1,y1');
[z2]=PivoteGauss(C2,y2');
p1=@(u) z1(1).*u.^2+z1(2).*u+z1(3);
p2=@(u) z2(1).*u.^2+z2(2).*u+z2(3);
u1=[x(1):0.001:x(3)];
u2=[x(3)+0.001:0.001:x(5)];
N2=length(u2);
U=[u1 u2(2:N2)];
p11=p1(u1);
p21=p2(u2);
P=p(U);
figure(),plot(u1,p11,'r'),holdon,grid
on,plot(u2,p21,'b'),plot(U,P,'g')
*function [P]= Interpolacion( X,Y)
%funcionque permite obtenerunpolinomioPque pase
por lospuntosdadospor losvectores'X' y 'Y'
n=length(X);%se obtiene ladimensiondel vectorX
A=vander(X');%se obtienelamatrizde Vandermonde
mediante lafuncion'vander'
Coe=inv(A)*Y';%se obtienenloscoeficientesdel polinomio
a construir
%a continuacionse creael polinomiocomounafuncion
f(x)
P=@(x) Coe(n);
for i=1:n-1
P=@(x) P(x)+Coe(n-i).*(x.^i);
end
end
4. *function [ X ] = Metodo_Jacobi( A,B,e )
%A es lamatriz de coeficientes
%B esel vectorde terminosindependientes
%e esel error
cont=0;
s=size(A);
n=s(1);
ind=0;
for k=1:n
B(k)=B(k)./A(k,k);
A(k,:)=A(k,:)./A(k,k);
A(k,k)=0;
end
M=-A;
Y0=zeros(n,1);
Y1=(M*Y0)+(B);
DY=Y1-Y0;
while norm(DY,inf)>e
Y1=(M*Y0)+(B);
DY=Y1-Y0;
Y0=Y1;
cont=cont+1;
if cont>500
ind=1;
break;
end
end
if ind==1
X='??';
disp('');
disp('Lamatrizingresadanoes diagonal dominante');
disp('El vectorde solucionesXnose puede calcular,
verifiqueque lamatrizseadiagonal dominate');
else
X=Y1;
end
end
*function [X] = Metodo_Gauss_Seidel( A,B,e )
%A es lamatriz de coeficientes
%B esel vectorde terminos independientes
%e esel error
s=size(A);
n=s(1);
cont=1;
ind=0;
D=diag(diag(A));
U=triu(A)-D;
L=tril(A)-D;
M=-inv(D+L)*U;
N=inv(D+L)*B;
Y0=zeros(n,1);
Y1=(M*Y0)+(N);
DY=Y1-Y0;
while norm(DY,inf)>e
Y1=(M*Y0)+(N);
DY=Y1-Y0;
Y0=Y1;
cont=cont+1;
if cont>500
ind=1;
break;
end
end
if ind==1
X='??';
disp('');
disp('Lamatrizingresadanoes diagonal dominante');
disp('El vectorde solucionesXnose puede calcular,
verifiqueque lamatrizseadiagonal dominate');
else
X=Y1;
end
end