Códigos Parcial

Descargar como pdf o txt
Descargar como pdf o txt
Está en la página 1de 7

function H=hermite(x, f, x0)

n = length(x);
z = zeros(2*n, 1);
Q = zeros(2*n, 2*n);

for i=1:n
Fp(i)=(f(x(i)+0.000001)-f(x(i)))/0.000001;
endfor

for i = 1:n
z(2*i-1) = x(i);
z(2*i) = x(i);
Q(2*i-1, 1) = f(x(i));
Q(2*i, 1) = f(x(i));
Q(2*i, 2) = Fp(i);
if i ~= 1
Q(2*i-1, 2) = (Q(2*i-1, 1) - Q(2*i-2, 1)) / (x(i) - x(i-1));
end
end

for j = 3:2*n
for i = j:2*n
Q(i, j) = (Q(i, j-1) - Q(i-1, j-1)) / (z(i) - z(i-j+1));
end
end

H = Q(1, 1);
producto = 1;
for i = 2:2*n
producto = producto * (x0 - z(i-1));
H = H + Q(i, i) * producto;
end

er=abs(H-f(x0));
end

-------------------------------------------------------------------------------------------------
function minimosCuadrados(X, Y)
errCuadratico = 0;
errEstandar = 0;
errorC = [];
errorE = [];
f = min(X)-0.5:0.01:max(X)+0.5
n = length(X);
C = polyfit(X, Y, 1)
V = polyval(C, X)

for i = 1 : n
errCuadratico = errCuadratico + (Y(i) - V(i)).^2;
errEstandar = errEstandar + (Y(i) - V(i));
errorC = [errorC, (Y(i) - V(i)).^2];
errorE = [errorE, (Y(i) - V(i))];
endfor

display(errEstandar);
display(errCuadratico);

figure(1)
plot(X, Y, '*',X,V,'g');
legend('Valores de P(x)','Recta M.C.');
grid on
figure(2)
plot(X, errorC, 'b--', X, errorE, 'r--')
legend('Error M.C.', 'Error Estándar')
grid on

-------------------------------------------------------------------------------------------------
function minimosCuadradosEXP(X, Y)
errCuadratico = 0;
errEstandar = 0;
errC = [];
errE = [];
f = min(X)-0.5:0.01:max(X)+0.5;
n = length(X);

Y2 = log(Y);
C = polyfit(X, Y2, 1);
V = polyval(C, X);

C(2) = exp(C(2));
E = @(x) C(2)*exp(C(1)*x);
Y1 = E(f);

for i = 1 : n
errCuadratico = errCuadratico + (Y(i) - E(X(i))).^2;
errEstandar = errEstandar + (Y(i) - E(X(i)));
errC = [errC, (Y(i) - E(X(i))).^2];
errE = [errE, (Y(i) - E(X(i)))];
endfor

figure(1)
plot(X, Y, 'o', f, Y1, 'r-')
legend('Valores de P(x)', 'Grafica de la aproximacion')
grid on

figure(2)
plot(X, errC, 'b--', X, errE, '*')
legend('Error M.C.', 'Error Estándar')
grid on

-------------------------------------------------------------------------------------------------
function X=mcc(f,a,b,n)
H = zeros(n+1,n+1);
y = zeros(n+1,1);
for i = 1:n+1
for j= 1:n+1
H(i,j) = (((b.^(i+j-1))-(a.^(i+j-1))) / (i+j-1));
endfor
endfor
for i=1:n+1
g=@(x) x.^(i-1);
h=@(x) g(x)*f(x);
y(i,1)= quad(h,a,b);
endfor
display(H);
display(b);
X= H\y;
-------------------------------------------------------------------------------------------------
mccORTONashe C = (a,b,f,f1)
n = length(f)
H = zeros(n,n)
val =0

for i=1:n
for j=1:n
g = @(x) f{i}(x)*f{j}(x)
H(i,j) = quad(g,a,b)

if i==j && H(i,j) <=0


val=1
endif

if j!=i && H(i,j) !=0


val=1
endif
endfor
endfor

if val ==0
for i=1:n
g =@(x) f{i}*f1(x)
C(i) = (1/H(i,i))*quad(g,a,b)
endfor
endif
-------------------------------------------------------------------------------------------------
Derivación continua
function aproxDx(f, h, x0)
metodo = input('Ingrese el método\n', 's')
switch metodo
case 'Inicio'
dx = (1/(2*h))*(-3*f(x0) + 4*f(x0 + h) - f(x0 + 2*h))
case 'Centrado'
dx = (1/(2*h))*(f(x0 + h) - f(x0 - h))
case 'Fin'
dx = (1/(2*h))*(f(x0 - 2*h) - 4*f(x0 - h) + 3*f(x0))
otherwise
error('Metodo no válido')
endswitch

-------------------------------------------------------------------------------------------------
Derivación discreta

function aproxDx2(X, Y, h, x0)


i = find(X == x0)
if isempty(i)
error('No existe x0')
else
if i == 1
dx = (1/(2*h))*(-3*Y(i) + 4*Y(i + 1) - Y(i + 2))
else
if i == length(X)
dx = (1/(2*h))*(Y(i - 2) - 4*Y(i - 1) + 3*Y(i))
else
dx = (1/(2*h))*(Y(i + 1) - Y(i - 1))
endif
endif
endif

Funciones Integrales:

quad(F,a,b): calcula la integral de F(x,y)entre a y b por Simpson

dblquad(F,xa,xb,ya,yb): calcula la integral doble de F(x,y) entre los límites respectivos.

triplequad(F,xa,xb,ya,yb,za,zb): calcula la integral triple…

trapz(X,Y): calcula la integral de los valores en (X,Y), a través del método de trapecio

También podría gustarte