Está en la página 1de 4

Alumno: Caja Torre Brayner Andy

%ejercicio 01
%encontrar las raices por Newton Raphson
clc
clear all
% f1=x^2+xy-10; % f1(x,y)=0
% f2=y+3*x*y^2-58; % f2(x,y)=0
x=2.5; y=1; Tabla=[x y Inf]; TOL=1e-14;
for i=1:10
J=[2*x+y x;3*y^2 1+6*x*y]; % [f1x f1y;f2x f2y]
F=[x^2+x*y-10; y+3*x*y^2-58];
dxy=J\-F; % Resuelve J*dxy=-F
x=x+dxy(1);
y=y+dxy(2);
err=norm(dxy,Inf); % error de sucesion
Tabla=[Tabla; x y err];
if err<TOL % cond.parada
break % interrumpe for
end
end
disp(Tabla)
Vector_Solucion=[x y]'
NumIte=i
% Ejercicio 2 evaluar usando poly y verificar con expand
% tt2=4*(x-1)*(x+2)^2*(x-3)
% tt3=2*(2*x-1)*(3*x+2)^2*(4*x-3)=2*2(x-0.5)*9*(x+2/3)^2*4*(x-3/4)
%---------------------------
tt2=4*poly([1 -2 -2 3])
syms z
tt2=4*(z-1)*(z+2)^2*(z-3)
ttt2=expand(tt2)
%----------------------------
tt3=144*poly([0.5 -2/3 -2/3 3/4])
syms z
tt3=2*(2*z-1)*(3*z+2)^2*(4*z-3)
ttt3=expand(tt3)

%Ejercicio 3
%Agregar un punto más (10,25)
clc
clear all, format long
x=[2 4 7 9 10]'
y=[10 20 40 30 25]'
M=[x.^4 x.^3 x.^2 x x.^0]
MM=vander(x)
p1=inv(M)*y
p2=M\y %resuelve el sistema lineal M*p=y
yy1=polyval(p1,x)
yy2=polyval(p2,x)
disp([yy1 yy2])
xx=min(x):0.1:max(x);
yy=polyval(p2,xx);
plot(x,y,'d',xx,yy), grid
legend('Data','Plinomio Interpolante')
%Ejercicio 4 : Agregar (10,60)
clc
clear all, format long
x=[2 4 7 9 10]'
y=[10 20 40 30 60]'
y1(1)=(y(2)-y(1))/(x(2)-x(1))
y1(2)=(y(3)-y(2))/(x(3)-x(2))
y1(3)=(y(4)-y(3))/(x(4)-x(3))
y1(4)=(y(5)-y(4))/(x(5)-x(4))

y2(1)=(y1(2)-y1(1))/(x(3)-x(1))
y2(2)=(y1(3)-y1(2))/(x(4)-x(2))
y2(3)=(y1(4)-y1(3))/(x(5)-x(3))

y3(1)=(y2(2)-y1(1))/(x(4)-x(1))
y3(2)=(y2(3)-y1(2))/(x(5)-x(2))

y4(1)=(y3(2)-y1(1))/(x(5)-x(1))
syms z
p=y(1)+y1(1)*(z-2)+y2(1)*(z-2)*(z-4)+y3(1)*(z-2)*(z-4)*(z-7)+y4(1)*(z-
2)*(z-4)*(z-7)*(z-9)
pp=expand(p)
yy=subs(p,x)

%ejercicio 5: Agregar (9,30)


clc
clear all, format long
x=[2 4 7 9]'
y=[10 20 40 30]'
syms z

L1=((z-4)*(z-7)*(z-9))/((2-4)*(2-7)*(2-9))
L2=((z-2)*(z-7)*(z-9))/((4-2)*(4-7)*(4-9))
L3=((z-2)*(z-4)*(z-9))/((7-2)*(7-4)*(7-9))
L4=((z-2)*(z-4)*(z-7))/((9-2)*(9-4)*(9-7))
p=L1*y(1)+L2*y(2)+L3*y(3)+L4*y(4)
pp=expand(p)
yy=subs(pp,x)

También podría gustarte