Documentos de Académico
Documentos de Profesional
Documentos de Cultura
F =
@(x)[7*x(1)+x(1)*x(2)+4*x(3)-24;x(1)^2+28*x(2)-3*x(2)*x(3)-12;-
3*x(1)*x(2)+x(2)*x(3)+13*x(3)-43]
x =
4
7
8
>> F(x)
ans =
64
32
33
>> JF=@(x) [x(2)+7 x(1) 4;2*x(1) 28-3*x(3) -3*x(2);-3*x(2) x(3)-3*x(1)
x(2)+13]
JF =
@(x)[x(2)+7,x(1),4;2*x(1),28-3*x(3),-3*x(2);-3*x(2),x(3)-
3*x(1),x(2)+13]
>> JF(x)
ans =
14 4 4
8 4 -21
-21 -4 20
>> x=x-JF(x)^-1*F(x)
x =
9.1944
-24.6536
5.4734
>> x=x-JF(x)^-1*F(x)
x =
3.7620
-18.6312
8.7603
>> x=x-JF(x)^-1*F(x)
x =
1.8113
-16.7521
9.4996
Programa:
function MtoNewtonRMultivariabe(x0,F,JF,tol,Nmax)
%Este trabajo es mio (Apolinario Pariona Javier)
%x0:Vector inicial con la que se evaluara la funcion
%JF:La Matriz jacobina
%F:funcion la cual vamos a interar
%nMax:numero maximo de interaciones
%tol:tolerancia para la raiz
k=0;
err=1;
fprintf('%33s\n','Metodo de Newton Raphson Multivariable')
fprintf('--------------------------------------------\n')
fprintf('%4d',k); fprintf('%12.8f',x0); fprintf('%12.8f\n',err);
while err>=tol & k<Nmax
x=x0-inv(JF(x0))*F(x0);
err=norm(x-x0)/norm(x);
%Actualizacio
k=k+1; x0=x;
fprintf('%4d',k); fprintf('%12.8f',x); fprintf('%12.8f\n',err);
end
if k>=Nmax
disp('se exedio el numero maximo de interaciones')
end
>> MtoNewtonRmultivariabe(x0,F,JF,10^-5,50)
Metodo de Newton Raphson Multivariable
-------------------------------------------------
1 9.19435737 -24.65360502 5.47335423 1.19723510
2 3.76203206 -18.63119154 8.76030155 0.41814076
3 1.81130556 -16.75210749 9.49961687 0.14514954
4 1.53119760 -16.30676663 9.53143881 0.02781362
5 1.52120891 -16.28637214 9.53157709 0.00119955
6 1.52119267 -16.28633627 9.53157667 0.00000208
EJERCICICO 2:
EJERCICUIO 3:
Programa:
function [T Pnewton P]=InterpNewton(X,Y)
N=length(X);
%X,Y son vectores fila de magnitud N
%grado de polinomio n=N-1
T=zeros(N);
T(:,1)=Y';
for j=2:N
for i=j:N
T(i,j)=(T(i,j-1)-T(i-1,j-1))/(X(i)-X(i-(j-1)));
end
end
syms x
p=1; P=0;
for k=1:N
if k~=1
p=p*(x-X(k-1));
end
P=P+p*T(k,k);
end
Pnewton=vpa(P,4);
P=expand(Pnewton);
P=vpa(P,4);
Solucion:
T =
1.0000 0 0
3.0000 5.0000 0
6.0000 10.0000 7.1429
Pnewton =
P =
f =
Inline function:
f(x) = 7.143*x^2 + 2.143*x + 1.0
>> f(0.2)
ans =
1.7143
>> f(0.5)
ans =
3.8572
EJERCICIO 4:
Parte A:
Programa:
T =
320.0000 0 0 0 0
490.0000 21.2500 0 0 0
540.0000 6.2500 -0.9375 0 0
500.0000 -5.0000 -0.7031 0.0098 0
480.0000 -2.5000 0.1563 0.0358 0.0008
Pnewton =
P =
f =
Inline function:
f(x) = 0.0008138*x^4 - 0.07487*x^3 + 1.589*x^2 + 18.11*x - 70.74
>> f(26)
ans =
530.2559
Parte b
PROGRAMA:
function splinelinealtramos(X,Y)
%X=input('Digite los datos del dominio');
%Y=input('Digite los datos de la imagen');
n=length(X);
%entre cada par de puntos contiguos debemos la recta que pasa por ellos
%y=mx+b
for k=1:n-1 %se toma hasta el penultimo de los puntos por lo tsnto su
derecha tendremos el ultimo punto
%puntos que se une (X(k),Y(k)) (X(k+1),Y(k+1))
m=(Y(k+1)-Y(k))/(X(k+1)-X(k)); %m es la pendiente
b=Y(k)-m*X(k); %se obtiene despejando la ecuacion y=mx+b
if b>0
fprintf('\n%fx+%f \t para x en [%.3f,%.3f]',m,b,X(k),X(k+1))
elseif b<0
fprintf('\n%fx-%f \t para x en [%.3f,%.3f]',m,abs(b),X(k),X(k+1))
else
fprintf('\n%fx \t \t para x en [%.3f,%.3f]',m,X(k),X(k+1))
end
end
fprintf('\n\n')
plot(X,Y,'*k',X,Y)
Ejecutando el programa:
X =
14
22
30
38
46
Y =
320
490
540
500
480
>> splinelinealtramos(X,Y)
>> f=inline('6.250000*x+352.500000')
f =
Inline function:
f(x) = 6.250000*x+352.500000
>> f(24)
ans =
502.5000
>> f=inline('-5.000000*x+690.000000')
f =
Inline function:
f(x) = -5.000000*x+690.000000
>> f(35)
ans =
515
Parte c
function y=SCubNatural(X,Y,x)
n=length(X)-1;
dy=zeros(n,1); h=zeros(n,1); dt=zeros(n+1,1); at=zeros(n,1);
bt=zeros(n+1,1);
for i=1:n
dy(i)=Y(i+1)-Y(i);
h(i)=X(i+1)-X(i);
if i>1
bt(i)=3*(dy(i)/h(i)-dy(i-1)/h(i-1));
dt(i)=2*(h(i-1)+h(i));
end
end
dt(1)=1;
dt(n+1)=1;
at=h; at(n)=0;
ct=h; ct(1)=0;
at,dt,ct
c=NewTridiagonaladc(at,dt,ct,bt);
for i=1:n
d(i)=(c(i+1)-c(i))/(3*h(i));
b(i)=dy(i)/h(i)-(1/3)*(2*c(i)+c(i+1))*h(i);
end
a=Y;
y=0;
for i=1:n
if i~=n
y=y+(x>=X(i) & x<X(i+1)).*(a(i)+b(i)*(x-X(i))+c(i)*(x-
X(i)).^2+d(i)*(x-X(i)).^3);
else
y=y+(x>=X(i) & x<=X(i+1)).*(a(i)+b(i)*(x-X(i))+c(i)*(x-
X(i)).^2+d(i)*(x-X(i)).^3);
end
end
bt,c,d,b
Ejecutando el programa:
at =
8
8
8
0
dt =
1
32
32
32
1
ct =
0
8
8
8
bt =
0
-45.0000
-33.7500
7.5000
0
c =
0
-1.1886
-0.8705
0.4520
0
d =
b =
y =
515.1730
517.3124