Halloween Party


¿Como te gustaría celebrar Halloween?, al lado de pingüinas o de diablitas?

Este año me animo por las diablitas xD.

Anuncios

Código Scilab – Método de la Secante



function y=f(x)
y=exp(-x^2)-x;
endfunction

function x = secante(x0,x1,tol)
j=2;
i=1;
x(1)=x0;
x(2)=x1;
ea(i)=100;
while abs(ea(i))>=tol
   x(j+1)=(x(j-1)*f(x(j))-x(j)*f(x(j-1)))/(f(x(j))-f(x(j-1)));
   ea(i+1)=abs((x(j+1)-x(j))/x(j+1))*100;
   j=j+1;
   i=i+1;     
end

printf(' i \t\t x(i) \t Error aprox (i) \n');
printf('%2d \t %11.7f \t \n',0,x(1));

for k=2:j;
    printf('%2d \t %11.7f \t %7.3f \n',k-1,x(k),ea(k-1));
end

endfunction

Código Scilab – Método de Iteración del Punto Fijo



function y=g(x)
y=(x^2-exp(x))/5;
endfunction

function x=puntofijo(x0,tol)
i=1;
ea(1)=100;
x(1)=x0;
while abs(ea(i))>=tol,
    x(i+1) = g(x(i));
    ea(i+1) = abs((x(i+1)-x(i))/x(i+1))*100;
    i=i+1;
end
printf(' i \t      X(i)       Error aprox (i) \n');
for j=1:i;
    printf('%2d \t %11.7f \t %7.3f \n',j-1,x(j),ea(j));
end
endfunction

Código Scilab – Método de la Regla Falsa



function y=f(x)
y=exp(-x)-log(x);
endfunction


function xr=reglafalsa(xai,xbi,tol)
i=1;
ea(1)=100;
if f(xai)*f(xbi) < 0
    xa(1)=xai;
    xb(1)=xbi;
    xr(1)=xa(1)-f(xa(1))*(xb(1)-xa(1))/(f(xb(1))-f(xa(1)));
    printf('It.              Xa           Xr            Xb            Error aprox \%\n');
    printf('%2d \t %11.7f \t %11.7f \t %11.7f \n',i,xa(i),xr(i),xb(i));
    while abs(ea(i))>=tol,
      if f(xa(i))*f(xr(i))< 0
         xa(i+1)=xa(i);
         xb(i+1)=xr(i);
      end
      if f(xa(i))*f(xr(i))> 0
         xa(1)=xr(i);
         xb(1)=xb(i);
	  end      
      xr(i+1)=xa(i+1)-f(xa(i+1))*(xb(i+1)-xa(i+1))/(f(xb(i+1))-f(xa(i+1)));
       ea(i+1)=abs((xr(i+1)-xr(i))/(xr(i+1)))*100;
      printf('%2d \t %11.7f \t %11.7f \t %11.7f \t %7.3f \n', i+1,xa(i+1),xr(i+1),xb(i+1),ea(i+1));
      i=i+1;
   end
else
   printf('No existe una raíz en ese intervalo');
end
endfunction

Código Scilab – Método de Newton-Raphson



function y=f(x)
y=exp(-x)-log(x);
endfunction

function y=df(x)
y=-exp(-x)-1/x;
endfunction

function x=newtonraphson(x0,tol);
i=1;
ea(1)=100;
x(1)=x0;
while abs(ea(i))>=tol;
    x(i+1)=x(i)-f(x(i))/df(x(i));
    ea(i+1)=abs((x(i+1)-x(i))/x(i+1)*100);
    i=i+1;
end
printf(' i  \t      X(i)      Error aprox (i) \n');
for j=1:i;
    printf('%2d \t %11.7f \t %7.3f \n',j-1,x(j),ea(j));
end
endfunction