0% found this document useful (0 votes)
28 views1 page

DERIVADA

This document describes a function that calculates the derivative of a function f at a point x using two methods: three-point and five-point formulas. It initializes variables like the step size h and calculates preliminary estimates of the derivative D. It then iteratively decreases h and recalculates D until the error E and residual R fall below a tolerance level. Finally, it returns a matrix L containing the step sizes, derivative estimates, errors, and residuals.

Uploaded by

Joel Huillca
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views1 page

DERIVADA

This document describes a function that calculates the derivative of a function f at a point x using two methods: three-point and five-point formulas. It initializes variables like the step size h and calculates preliminary estimates of the derivative D. It then iteratively decreases h and recalculates D until the error E and residual R fall below a tolerance level. Finally, it returns a matrix L containing the step sizes, derivative estimates, errors, and residuals.

Uploaded by

Joel Huillca
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DERIVADA DE TRES PUNTOS

function [L,n]=derivada(f,x,tolerancia)
itmax=15;
h=1;
H(1)=h;
D(1)=(feval(f,x+h)-feval(f,x-h))/(2*h);
E(1)=0;
R(1)=0;
for n=1:2
h=h/10;
H(n+1)=h;
D(n+1)=(feval(f,x+h)-feval(f,x-h))/(2*h);
E(n+1)=abs(D(n+1)-D(n));
R(n+1)=2*E(n+1)*(abs(D(n+1))+abs(D(n))+eps);
end
n=2;
while ((E(n)>E(n+1))&(R(n)>tolerancia))&n<itmax;
h=h/10;
H(n+2)=h;
D(n+2)=(feval(f,x+h)-feval(f,x-h))/(2*h);
E(n+2)=abs(D(n+2)-D(n+1));
R(n+2)=2*E(n+2)*(abs(D(n+2))+abs(D(n+1))+eps);
n=n+1;
end
n=length(D)-1;
L=[H' D' E' R'];
DERIVADA DE CINCO PUNTOS
function [L,n]=derivada(f,x,tolerancia)
itmax=15;
h=1;
H(1)=h;
D(1)=(-feval(f,x+2*h)+8*feval(f,x+h)-8*feval(f,x-h)+feval(f,x-2*h))/(12*h);
E(1)=0;
R(1)=0;
for n=1:2
h=h/10;
H(n+1)=h;
D(n+1)=(-feval(f,x+2*h)+8*feval(f,x+h)-8*feval(f,x-h)+feval(f,x-2*h))/(12*h);
E(n+1)=abs(D(n+1)-D(n));
R(n+1)=2*E(n+1)*(abs(D(n+1))+abs(D(n))+eps);
end
n=2;
while ((E(n)>E(n+1))&(R(n)>tolerancia))&n<itmax;
h=h/10;
H(n+2)=h;
D(n+2)=(-feval(f,x+2*h)+8*feval(f,x+h)-8*feval(f,x-h)+feval(f,x-2*h))/(12*h);
E(n+2)=abs(D(n+2)-D(n+1));
R(n+2)=2*E(n+2)*(abs(D(n+2))+abs(D(n+1))+eps);
n=n+1;
end
n=length(D)-1;
L=[H' D' E' R'];

You might also like