Download - Tarea Final
Universidad del Caribe
PROGRAMA EDUCATIVO:Ingeniera Industrial
ASIGNATURA:Mtodos numricos por computadora.II0423DOCENTE:M. en C. Ivn Enrique Dzib Daz.
FECHA DE ENTREGA:Viernes 5 de Julio del 2013
ESTUDIANTE:
El siguiente documento fue realizado en la Universidad del Caribe en Cancn, Quintana Roo, Mxico en el periodo Verano 2013 por la estudiante: Mara de los ngeles Emma Rodrguez Daz, en la asignatura de mtodos numricos por computadora (II0423) bajo la docencia del M. en C. Ivn Enrique Dzib Daz del Departamento de Ciencias Bsicas e Ingenieras del Programa Educativo de Ingeniera Industrial.
CONTENIDO
PRIMER PARCIAL
GRAFICA DE UNA FUNCION CON N ESPACIOS IGUALES
FORMULA GENERAL
//Funcion Form. Gral
function gral(a, b, c) dividendo = 2 * a;if (dividendo 0) then x1 = (-b + sqrt(b^2 - 4 * a * c))/dividendo; x2 = (-b - sqrt(b^2 - 4 * a * c))/dividendo; disp([x1, x2]);else disp('imposible division entre 0 Verificar variable a'); x1 = 0; x2=0;endendfunction
PUNTO MEDIO- BISECCION //Punto mediofunction res=f(x) res=sin(x)endfunction
function resp=puntomedio(a, b) h=(b-a)/2; x1=a+h; resp=2*h*f(x1)endfunction
//Biseccion
function y=f(x)y=sin (x);endfunction
function raiz=bisection(a, b, tol) an = a; bn = b; if f(an)*f(bn) < 0 then raiz = (an + bn)/2; while (abs(f(raiz)) > tol) if f(an)*f(raiz) < 0 then bn = raiz; else an = raiz; end raiz = (an + bn)/2; end else disp('El teorema no garantiza una raiz') raiz = "no tenemos" endendfunction
//Biseccion function res=fun(x) // res = (x^3) + (4*x^2) - 10; //res = sqrt(x) - cos(x); //res = x^2 - (2^x); //res = x^2 - 1; //res = sqrt(x)-cos(x)-2 //res=2*cos(x); //res=(x^4)+(2*x^2)-x-3 //res=(x^2)-x-90; res=(x^3)-(x^2)-180;endfunction
function raiz=bisection(a, b, tol) if (fun(a) * fun(b) >= 0) then disp('El teorema no garantiza RAICES'); raiz = "NO RAIZ"; else an=a; bn=b; rn = (an + bn)/2; while (abs(fun(rn)) > tol) if (fun(an) * fun(rn) < 0) then bn = rn; rn = (an + bn) / 2; else an = rn; rn = (an + bn) / 2; end disp(rn); end raiz = rn; endendfunction
//bisection (a=2, b=0, Tol=0.001)function y=f(x) y=x^3+4*x^2-10endfunction
function raiz=bisection(a, b, tol) an = a; bn = b; if f(an)*f(bn) < 0 then raiz = (an + bn)/2; while (abs(f(raiz)) > tol) if f(an)*f(raiz) < 0 then bn = raiz; else an = raiz; end raiz = (an + bn)/2; end else disp('El teorema no garantiza una raiz') raiz = "no tenemos" endendfunction//Solucin=ans=1.3652344
//Necesitamos la grafica para ver los valores de a y b x=linspace(0,3,100)y=sqrt(x)-cos(x);plot(x)
//de a=0.5, b=1.5 tol=0.001
function y=f(x) y=sqrt(x)-cos(x)endfunction raiz = bisection(a,b,tol) an = a; bn = b; if f(an)*f(bn) < 0 then raiz = (an + bn)/2; while (abs(f(raiz)) > tol) if f(an)*f(raiz) < 0 then bn = raiz; else an = raiz; end raiz = (an + bn)/2; end else disp('El teorema no garantiza una raiz') raiz = "no tenemos" endendfunction //bisection(0.5,1.5,0.001)ans =0.6416016
//sacar valores para encontrar a y b
x=linspace(0,3,100) y=x^2-2^x;plot(x,y)
//viendo la grafica determinamos los valores de a=1 b=2.5
function y=f(x) y=x^2-2^x;endfunction
function raiz=bisection(a, b, tol) an = a; bn = b; if f(an)*f(bn) < 0 then raiz = (an + bn)/2; while (abs(f(raiz)) > tol) if f(an)*f(raiz) < 0 then bn = raiz; else an = raiz; end raiz = (an + bn)/2; end else disp('El teorema no garantiza una raiz') raiz = "no tenemos" endendfunction
//aproximar sqrt de 3 con un error de 10^-5
x=linspace(0,3,100)y=sqrt3plot
function y=f(x) y=x^2-2^x;endfunction
function raiz=bisection(a, b, tol) an = a; bn = b; if f(an)*f(bn) < 0 then raiz = (an + bn)/2; while (abs(f(raiz)) > tol) if f(an)*f(raiz) < 0 then bn = raiz; else an = raiz; end raiz = (an + bn)/2; end else disp('El teorema no garantiza una raiz') raiz = "no tenemos" endendfunction
TAYLORfunction errorM=ftaylor(x)//Pido que me arroje errorM usando ftaylor//e^x es aprox a 1+x si x tiende a 0x=linspace((exp(1))-0.1,(exp(1))+0.1,8)//de -0.1 hasta 0.1 con 8 espacios entre ellosy=x/exp(1);z=log(x);error=abs(y-z);errorM=max(error);endfunction
NEWTON- -NNEWTONfunction y=f(x) //y=x^2-6; y=(x^4)+(2*(x^2))-x-3 //y=exp(x)+2^(-x)+(2*cos(x))-6; //y=log(x-1)+cos(x-1)endfunctionfunction yp=fp(x) //yp=2*x;// derivar manualmente yp=(4*(x^3))+(4*x)-1 //yp=exp(x)-((0.5*x)*(log(x)))-2*sin(x) //yp=(1/(x-1))-sin(x-1)endfunction function raiz=Anewton(r0, tol) if fp(r0)==0 disp('condicion incial inadecuada') break endrn=r0-(f(r0))/(fp(r0));while(abs(f(rn))>tol) if fp(rn)==0 rn=rn+0.1; elsern=rn-(f(rn))/(fp(rn));enddisp(f(rn)) endraiz=rn;endfunction
function raiz=anewton(r0, tol) N = 0; while abs(fp(r0)) < 10^(-5) r0 = r0 + 0.1; N = N+1; if N > 100 then disp('maximo de iteraciones'); break end end rn = r0 - (f(r0)/fp(r0)); while abs(f(rn)) > tol if abs(fp(r0)) == 0 then rn = rn + 0.1; end rn = rn - f(rn)/fp(rn); end raiz = rn;endfunction
//NNewton
function y=f(x) //y = exp(x)-x-1; y=(x^4)+(2*(x^2))-x-3; //y=exp(x)+2^(-x)+(2*cos(x))-6 //y=log(x-1)+cos(x-1)endfunction;
function yp=fp(x)// yp = exp(x)-1; yp=(4*(x^3))+(4*x)-1; //yp=exp(x)-((0.5*x)*(log(x)))-2*sin(x) //yp=(1/(x-1))-sin(x-1)endfunction;function ypp=fpp(x) //ypp = exp(x); ypp=(12*(x^2))+4; //ypp=exp(x)-0.5+(0.5*log(x))-(2*cos(x)) //ypp=-(1/(x-1)^2)-cos(x-1)endfunction
//tolerancia = tol o tambien puede ser n = num de iteracionesfunction raiz=NNewton(r0, tol) if fp(r0)==0 then disp('condicion inicial inadecuada') //r0 = r0 + 0.1; end i=1; rn(i) = r0 - ( (f(r0) * fp(r0) ) / ( ((fp(r0))^2) - ( f(r0) * fpp(r0) ) ) ); while ( abs( f(rn(i)) ) > tol ) //rn(i+1)= rn(i) - ( (f(r0) * fp(r0) ) / ( ((fp(r0))^2) - ( f(r0) * fpp(r0) ) ) ); rn(i+1)= rn(i) - ( (f(rn(i)) * fp(rn(i)) ) / ( ((fp(rn(i)))^2) - ( f(rn(i)) * fpp(rn(i)) ) ) ); //disp(rn(i)); i=i+1; end raiz=rn; endfunction
function raiz=Nanewton(r0, tol, N) // N es mi numero maximo de iteraciones rn = r0; cont = 0; // contador de numero de iteraciones while abs(f(rn)) > tol & cont < N rn = rn - ((f(rn)*fp(rn))/((fp(rn)*fp(rn))-(f(rn)*fpp(rn)))); cont = cont + 1; end raiz = rn;endfunction
INTERPOLACION//INTP1function resp=intp1(x, y, xp) // x=[x0,x1],y=[y0,y1] if x(1)==x(2) then resp=('x0 debe ser menor a x1') else if x(1)