Metodos Numericos (MATLAB)- VIDEOTUTORIAL
PARA VER EL VIDEOTUTORIAL DAR CLIC EN LA IMAGEN
METODO DE EULERclear alldisp('METODO DE EULER')clcsyms xsyms yf=inline(input('ingrese la derivada:','s'));x=input('ingrese el valor de x:');y=input('ingrese el valor de y:');h=input('ingrese el valor de h:');n=input('ingrese numero de iteraciones:');clcdisp('x(n) y(n) y´(n) hy´(n)');for i=1:ny1=feval(f,x,y);hy1=h*y1;fprintf('\n%0.1f %0.4f %0.4f %0.4f ',x,y,y1,hy1);y=y+hy1;x=x+h;endMETODO DE NEWTON-COTESclcclear alldisp('METODO DE NEWTON-COTES')syms xf=inline(input('ingrese la funcion:','s'));a=input('ingrese intervalo inferior:');b=input('ingrese intervalo superior:');n=1h=(b-a)/3x0=ax1=x0+hx2=x1+hx3=x2+hx4=x3+hf0=feval(f,x0)f1=feval(f,x1)f2=feval(f,x2)f3=feval(f,x3)f4=feval(f,x4)I1=(h/2)*(f0+f1)error=(-1/12)*(h^5)*((f2-(2*f1)+f0)/(h^2))I1=I1+errorn=2I2=(h/3)*(f0+4*f1+f2)error=(-1/90)*(h^5)*((f4-(4*f3)+(6*f2)-(4*f1)+f0)/(h^4))I2=I2+errorMETODO DE EULER MODIFICADOclear all
disp('METODO DE EULER MODIFICADO')
clc
syms x
syms y
f=inline(input('ingrese la derivada:','s'));
x=input('ingrese el valor de x:');
y=input('ingrese el valor de y:');
h=input('ingrese el valor de h:');
n=input('ingrese numero de iteraciones:');
clc
disp('x(n) y´(n) hy´(n) y(n+1),p hy´(n+1),p y(n+1),c');
for i=1:n
s=h+x;
y1=feval(f,x,y);
hy1=h*y1;
y2=y+hy1;
y3=feval(f,s,y2);
hy2=y3*h;
yn=y+((hy1+hy2)/2);
fprintf('\n%0.1f %0.4f %0.4f %0.4f %0.4f %0.4f',x,y,hy1,y2,hy2,yn);
y=yn;
x=x+h;
endMETODO DE LA SECANTEclc
syms x
f=inline(input('ingrese la funcion :','s'));
x0=input('ingrese intervalo inferior:');
x1=input('ingrese intervalo superior:');
tol=input('ingrese la tolerancia:');
fx0=feval(f,x0);
fx1=feval(f,x1);
n=1;
if(abs(fx0))<(abs(fx1)) fx2=900; disp('n x0 x1 x2 f(x0) f(x1) f(x2) ') while (abs(fx2))>tol
x2=x1-((x1-x0)/(fx1-fx0))*fx1;
fx2=feval(f,x2);
fprintf('\n%d %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f',n,x0,x1,x2,fx0,fx1,fx2)
x0=x1;
x1=x2;
fx0=feval(f,x0);
fx1=feval(f,x1);
n=n+1;
end
else
disp('NO SE PUEDE REALIZAR POR ESTE METODO');
disp('|F(X0)| TIENE QUE SER MENOR A |F(X1)|');
endMETODO DE SIMPSON 3/8clc
disp('METODO DE SIMPSON 3/8')
f=inline(input('ingrese la funcion a integrar:','s'));
a=input('ingrese intervalo inferior:');
b=input('ingrese intervalo superior:');
h=input('digite el valor del paso:');
c=0;suma=0;sumav=0;
s=a;
while (s<=b) c=c+1; s=s+h; end x=a:h:b; if(rem((c-1),3)~=0) disp('\n\nERROR') disp('SE REQUIERE UN NUMER0 DE PAREJAS DIVISIBLE POR 3') disp('EJECUTE DE NUEVO Y CAMBIE EL PASO') break; else p=4; for(i=1:c) fi=feval(f,x(i)) if(i==1 | i==c) suma=suma+fi; else if(i==p) sumav=sumav+(fi*2); p=p+3; else sumav=sumav+(fi*3); end end end end suma=suma+sumav; integral=(3*h/8)*suma; t0=feval(f,x(1)); t1=feval(f,x(2)); t2=feval(f,x(3)); t3=feval(f,x(4)); t4=feval(f,x(5)); f4=(t4-(4*t3)+(6*t2)-(4*t1)+t0)/(h^4); error=-((b-a)/80)*(h^4)*f4; integral=integral+error
METODO DE SIMPSON 1/3clc
disp('METODO DE SIMPSON 1/3')
f=inline(input('ingrese la funcion a integrar:','s'));
a=input('ingrese intervalo inferior:');
b=input('ingrese intervalo superior:');
h=input('digite el valor del paso:');
c=0;suma=0;sumav=0;
s=a;
while (s<=b) c=c+1; s=s+h; end x=a:h:b; if(rem(c,2)==0) disp('ERROR') disp('SE REQUIERE UN NUMERO PAR DE PAREJAS') disp('EJECUTE DE NUEVO Y CAMBIE EL PASO') break; else for(i=1:c) fi=feval(f,x(i)); if(i==1 | i==c) suma=suma+fi; else if(rem(i,2)==0) sumav=sumav+(fi*4); else sumav=sumav+(fi*2); end end end end suma=suma+sumav; integral=(h/3)*suma; t0=feval(f,x(1)); t1=feval(f,x(2)); t2=feval(f,x(3)); t3=feval(f,x(4)); t4=feval(f,x(5)); f4=(t4-(4*t3)+(6*t2)-(4*t1)+t0)/(h^4); error=-((b-a)/180)*(h^4)*f4; integral=integral+error
METODO DE RUUGE-KUTTAclc
disp('METODO DE RUUGE-KUTTA')
syms x
syms y
f=inline(input('ingrese la derivada:','s'));
x=input('ingrese el valor de x:');
y=input('ingrese el valor de y:');
h=input('ingrese el valor de h:');
n=input('ingrese numero de iteraciones:');
clc
disp('x(n) k1 k2 k3 k4 ');
for i=1:n
k1=h*(feval(f,x,y));
z=x+(1/2*(h));
w=y+(1/2*(k1));
k2=h*(feval(f,z,w));
w=y+(1/2*(k2));
k3=h*(feval(f,z,w));
z=x+h;
w=y+k3;
k4=h*(feval(f,z,w));
fprintf('\n%0.1f %0.4f %0.4f %0.4f %0.4f %0.4f',x,y,k1,k2,k3,k4);
x=x+h;
y=y+((1/6)*(k1+2*k2+2*k3+k4));
endMETODO DE BAIRSTOWclc
tol=10^-3;
x1=input('ingrese x1:');
x2=input('ingrese x2:');
x3=input('ingrese x3:');
x4=input('ingrese x4:');
x5=input('ingrese x5:');
r=input('ingrese r:');
s=input('ingrese s:');
b1=1;b0=1;
while(abs(b1>tol) & abs(b0>tol))
b4=x1;
b3=(b4*r)+x2;
b2=(b3*r)+(b4*s)+x3;
b1=(b2*r)+(b3*s)+x4;
b0=(b1*r)+(b2*s)+x5;
c4=b4;
c3=(c4*r)+b3;
c2=(c3*r)+(c4*s)+b2;
c1=(c2*r)+(c3*s)+b1;
dr=((-b1*c2)-(-b0*c3))/((c2*c2)-(c1*c3));
ds=((c2*-b0)-(c1*-b1))/((c2*c2)-(c1*c3));
r=dr+r;
s=ds+s;
end
p=-r;
q=-s;
fprintf('POLINOMIO = %0.0fX^4 +%0.2fX^3 + %0.2fX^2 + %0.2fX +%0.2f\n',x1,x2,x3,x4,x5);
fprintf('LA FORMA BUSCADA ES \n(%0.0fX^2 + %0.1fX + %0.2f) Y %0.0fX^2 + %0.1fX + %0.2f',b4,b3,b2,x1,p,q);
fprintf('\nLAS RAICES APROXIMADAS SON:\n\n');
raiz1=(-b3+sqrt((b3^2)-4*b4*b2))/2*b4
raiz2=(-b3-sqrt((b3^2)-4*b4*b2))/2*b4
raiz3=(-p-sqrt((p^2)-4*x1*q))/2*x1
raiz4=(-p-sqrt((p^2)-4*x1*q))/2*x1METODO DE BISECCIÓN
f=inline(input('ingrese la funcion:','s'));
a=input('ingrese intervalo inferior:');
b=input('ingrese intervalo superior:');
tol=input('ingrese la tolerancia:');
fa=feval(f,a);
fb=feval(f,b);
if (sign(fa)==sign(fb))
disp('no se garantiza el teorma de bolzano:');
break;
end
fc=10;
n=1;
disp('n an bn cn f(c)n');
while(n~=8)
c=(a+b)/2;
fc=feval(f,c);
fprintf('\n%d %0.4f %0.4f %0.4f %0.4f',n,a,b,c,fc);
if (fc==0)
fprintf('%f es un cero de f',c);
break;
end
if (sign(fc)==sign(fa))
s=c;
t=b;
else
if(sign(fc)~=sign(fb))
s=a;
t=c;
end
end
n=n+1;
a=s;
b=t;
fa=feval(f,a);
fb=feval(f,b);
endPOSDATA: no se les olvide agradecer...............n=3I3=((3*h)/8)*(f0+(3*f1)+(3*f2)+f3)error=(-3/80)*(h^5)*((f4-(4*f3)+(6*f2)-(4*f1)+f0)/(h^4))I3=I3+error

