Sei sulla pagina 1di 5

INTERPOLACION:

clear all;
clc;
fprintf('Interpolacion con el Metodo de Aproximacion Polinomial Simple\n\n');
n=input('Numero de puntos que se tienen: ');
for i=1:n
x(1,i)=input('dame los valores de xi:');
end
for i=1:n
xi(1,i)=input('dame los valores de f(xi):');
end
%imprimiendo los Valores x, xi
x
xi
xint=input('Numero para el que desea interpolar x: ');
%determinando los parametros a0,1,2
i=1;
while i<=n
a(i,1)=1;
j=2;
while j<=n
a(i,j)=a(i,j-1)*x(1,i);
j=j+1;
end
a(i,n+1)=xi(1,i);
i=i+1;
end
%Resolviendo mediante el metodo de Gauss-jordan
c=n+1;
f=n;
for k=1:c-1
a(k,:)=a(k,:)/a(k,k);
for j=k+1:f
a(j,:)=a(j,:)-a(k,:)*a(j,k);
j=j+1;
end
k=k+1;
end
for k=f:-1:2
for j=k-1:-1:1
a(j,:)=a(j,:)-a(k,:)*a(j,k);
j=j-1;
end
k=k-1;
end
r=0;
for m=1:n-1
r=r+(a(m+1,n+1))*xint^m;
end
r=r+a(1,n+1);
fprintf('\n\nresultado xi: %d\n',r);
%Graficando Resultados
plot(x,xi)
grid
xlabel('x');ylabel('y')

PUNTO FIJO:
xf(1)=input('Ingrese el valor inicial: ');
tol=input('Ingrese el porcentaje de error: ');
syms x;
f=input('Ingrese la funcin f(x), despejada g(f(x)): ');
i=1;
ea(1)=100;
while abs(ea(i))>=tol,
xf(i+1) = subs(f,x,xf(i));
ea(i+1) = abs((xf(i+1)-xf(i))/xf(i+1))*100;
i=i+1;
end
fprintf('i xf(i) Error aprox (i) \n');
for j=1:i;
fprintf('%2d \t %11.7f \t %7.3f \n',j-1,xf(j),ea(j));
end
POLINOMIO DE TAYLOR:
disp('CALCULO DEL POLINOMIO DE TAYLOR')
syms x
f=input('Dame la funcion');
n=input('dame el grado del polinomio')
a=input('dame el punto para evaluar')
taylor(f,n+1,a)
BISECCION:
disp('Biseccion "metodo para obtener raices" ')
format short;
a=input('Introduzca el valor de a: ');
b=input('Introduzca el valor de b: ');
cont=input('Introduzca el nmero de iteraciones cont: ');
fun=input('Introduzcal a funcion f(x)=','s');
f=inline(fun);
for k=1:cont
c=(a+b)/2;
e=abs((b-a)/2);
A(k,:)=[k a b c f(c) e];
if f(a)*f(c)<0
b=c;
else
a=c;
end
end
fprintf('\n \tk \ta \tb \tc \tf(c) \terror \n')
disp(A)
fprintf('Solucin:\n c=%8.5f\n',c)
fprintf('f(c)=%8.5f\n',f(c))
fprintf('error=%8.5f\n',e)
SISTEMAS DE ECUACIONES:
clc,clear
disp( 'Solucionador de sistemas de ecuaciones')
n=input('Ingrese el nmero de ecuaciones: ')
disp('Ingrese los coeficientes de las ecuaciones: ')
for i=1:n

for j=1:n
fprintf('A (%d,%d): ',i,j)
A(i,j)=input('');
end
end
disp('Ingrese los trminos independientes de las ecuaciones: ')
for k=1:n
fprintf('A (%d,%d): ',k,n+1)
A(k,n+1)=input('');
end
disp('La matriz ampliada que se form es la siguiente: ')
A=A
disp('A continuacin de realizar la eliminacion hacia adelante. ')
x=1;
while(x<n)
for s=1:n-1
for l=x:n-1
A(l+1,:)=A(s,:)*(-A(l+1,s)/A(s,s))+A(l+1,:);
end
x=x+1;
end
end
disp('La matriz trinagular superior que se form fue la siguiente: ')
A=A
X(n)=A(n,n+1)/A(n,n);
for h=n-1:-1:1
S=A(h,n+1);
for f=n:-1:1
S=S-A(h,f)*X(f);
end
S=S/A(h,h);
X(h)=S;
end
disp('Resultado:')
disp('----------')
for r=1:n
fprintf('X%d = %f ',r,X(r))
end
disp('Fin del programa.')
RUNGE KUTTA SEGUNDO ORDEN:
function f
fprintf('\n \tRESOLUCION DE ECUACIONES DIFERENCIALES POR MEDIO RUNGE-KUTTA DE OR
DEN 4\n')
f=input('\n Ingrese la ecuacion diferencial dy/dx=\n','s');
x0=input('\n Ingrese el primer punto x0:\n');
x1=input('\n Ingrese el segundo punto x1:\n');
y0=input('\n Ingrese la condicion inicial y(x0):\n');
n=input('\n Ingrese el numero de pasos n:\n');
h=(x1-x0)/n;
xs=x0:h:x1;
fprintf('\n''it x0 y(x1)');
for i=1:n
it=i-1;
x0=xs(i);
x=x0;
y=y0;

k1=h*eval(f);
x=xs(i+1);
y=y0+k1;
k2=h*eval(f);
y0=y0+(k1+k2)/2;
fprintf('\n%2.0f%10.6f%10.6f\n',it,x0,y0);
end
RUNGE KUTTA CUARTO ORDEN:
function f
fprintf('\n \tRESOLUCION DE ECUACIONES DIFERENCIALES POR MEDIO RUNGE-KUTTA DE OR
DEN 4\n')
f=input('\n Ingrese la ecuacion diferencial\n','s');
x0=input('\n Ingrese el primer punto x0:\n');
x1=input('\n Ingrese el segundo punto x1:\n');
y0=input('\n Ingrese la condicion inicial y(x0):\n');
n=input('\n Ingrese el numero de pasos n:\n');
h=(x1-x0)/n;
xs=x0:h:x1;
fprintf('\n''it x0 y(x1)');
for i=1:n
it=i-1;
x0=xs(i);
x=x0;
y=y0;
k1=h*eval(f);
x=x0+h/2;
y=y0+k1/2;
k2=h*eval(f);
x=x0+h/2;
y=y0+k2/2;
k3=h*eval(f);
x=x0+h;
y=y0+k3;
k4=h*eval(f);
y0=y0+(k1+2*k2+2*k3+k4)/6;
fprintf('\n%2.0f%10.6f%10.6f\n',it,x0,y0);
end
fprintf('\n El punto aproximado y(x1) es = %8.6f\n',y0);
SIMPOSN 1/3:
clear all;
clc;
fprintf('Calculo de la integral por el metodo de Simpson de 1/3\n\n');
f=input('introduce la funcion:','s');
a=input('lime inferior:');
b=input('limite superior:');
c=input('numero de segmentos a dividir (numero par):');
h=(b-a)/c;
z=0;
x=a;
for i=1:c;
if (-1)^i==1
k=eval(f);
z=z+k;

end
x=h*i;
end
zz=0;
x=a;
for i=2:c;
if (-1)^i==-1
k=eval(f);
zz=zz+k;
end
x=h*i;
end
x=a;
if x==a
d=eval(f);
end
x=b;
if x==b
e=eval(f);
end
z=z*4;
v=zz*2;
z=z+v+d+e;
z=z/(3*c);
z=z*(b-a)
fprintf('Resultado ');

Potrebbero piacerti anche