Alvarito

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

%Aprox.

Funcional
%Aprox simple 2do grado
%hallar la segunda derivada eval en x=3.7
clc,clear
x=[3 4.2 5]'
y=[6.57735 8.8725 10.44721]'
A=[ones(3,1) x x.^2];
%SEL A.x=y => x=inv(A)*y
a=inv(A)*y; %coeficiente del polinomio
fprintf('P(x)=%f + %fx + %fx^2 \n',a(1),a(2),a(3))
xint=3.7;
% Px=a(1)+a(2)*xint+a(3)*xint^2;
fprintf('P"(%f)=%f\n',xint,2*a(3))

%grfica
% plot(x,y,'*r')
% xx=1:0.1:10;
% yy=a(1)+a(2)*xx+a(3)*xx.^2;
% hold on
% plot(xx,yy)
% grid on
% hold off
%polinomios de Newton de primer grado
clc,clear
x=[1 5]
y=[8 20]
a0=y(1);
a1=diff(y)/diff(x)
fprintf('P(x)=%f + %f(x-%f)\n',a0,a1,x(1)) %x0=x(1)
xint=3 %valor a interpolar
Px=a0+a1*(xint-x(1))
%Polinomios de Lagrange
clc,clear
n=input('Ingrese grado del polinomio:');
disp('Ingrese vector x')
for i=1:n+1
fprintf('x(%d)=',i);
x(i)=input('');
end
disp('Ingrese vector y')
for i=1:n+1
fprintf('y(%d)=',i);
y(i)=input('');
end
x,y
xint=input('Ingrese valor a interpolar:')
for i=1:n+1
L(i)=1;
for j=1:n+1
if j~=i
L(i)=L(i)*(xint-x(j))/(x(i)-x(j));
end
end
end
L;
Px=sum(L.*y);
fprintf('P(%f)=%f\n',xint,Px)
%Aprox. Funcional
%Aprox simple - 1er grado
clc,clear
x=[1 5]'
y=[8 20]'
A=[ones(2,1) x];
%SEL A.x=y => x=inv(A)*y
a=inv(A)*y; %coeficiente del polinomio
a0=a(1);a1=a(2);
fprintf('P(x)=%f + %f x\n',a0,a1)
xint=3;
Px=a0+a1*xint;
fprintf('P(%d)=%f\n',xint,Px)
Ingrese grado del polinomio:2

Ingrese vector x

x(1)=4

x(2)=12

x(3)=20

Ingrese vector y

y(1)=10.668

y(2)=11.622

y(3)=13.539

x=

4 12 20

y=

10.6680 11.6220 13.5390

Ingrese valor a interpolar:18

xint =

18

P(18.000000)=12.969469

>> x=[1 5 20]

x=

1 5 20

>> diff(x)

ans =

4 15

>> y=[8 20 50]

y=

8 20 50

>> diff(y)

ans =

12 30

>> diff(y,2)

ans =
18

>>

You might also like