Vous êtes sur la page 1sur 28

D epartamento D e E lctrica Y E lectrnica

Alumno

METODOS NUMERICOS Stalin Xavier Caza Negrete


: Nivel :

Tercero
Ao 2013

PRIMER DEBER DE METODOS NUMERICOS


Stalin Xavier Caza Negrete. ESPE

Ingeniera Electrnica en Automatizacin y Control

18 de septiembre de 2013

METODOS NUMERICOS

Stalin Xavier Caza Negrete

EJERCICIOS
1. Crear una funcin M-le con la que se pueda gracar la siguiente funcin:
x(t) = 2sin( 2t ) + sin(3t) 3 y (t) = 2cos( 2t ) + cos(2t) 3

f (t) =

donde t [a, b] y a, b reales. Los parametros de entrada sern los extremos del intervalo y h el nmero de puntos a utilizar.
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

function [ ] =grafun1( a,b,n ) %ingrese el intervalo y numeros de puntos a utilizar. %de la forma: grafica4( a,b,n ) t = linspace(a,b,n); plot(2.*sin((2.*t)/3)+sin(3.*t),2.*cos((2.*t)/3)+cos(2.*t),'or'); grid on; title('Grafica De La Funcion Paramtrica'); xlabel('Eje De Abscisas'); ylabel('Eje De Ordenadas'); end

USO DE LA FUNCION EN MATLAB

>> grafun1(-2,2,5000)

METODOS NUMERICOS

Stalin Xavier Caza Negrete

2. Tabla de conversin de temperaturas. La relacin de diversas escalas de temperatura con la escala Celsius (C) es la siguiente:
9 Escala Farenheit:F = 5 C + 32

Escala Kelvin: K = C + 273, 15


C Construir un programa en Matlab que permita pasar de Escala Reamur: R = 4 5

una escala a otra. El programa debe solicitar al usuario el ingreso de la informacin necesaria para su funcionamiento. Para transformar las escalas entre s, se utiliza el comando switch y se lo subdivide en 4 casos, que son las cuatro escalas solicitadas. Primeramente, se solicita a travs de la instruccin input en que escala se ingresa los datos, luego se pide su valor para luego y con la instruccin display se presenta en las otras tres escalas su valor.
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

clc; clear all; disp(' ESCUELA POLITECNICA DEL EJERCITO ') disp(' DEBER DE METODOS NUMERICOS') disp('---------------------------------------------------------------------') disp('SEGUNDO EJERCICIO') disp('Programa para convertir unidades de temperatura') disp('---------------------------------------------------------------------') disp('Seleccione la escala desde la cual se transformara'); disp('1.-Celsius') disp('2.-Farenheit') disp('3.-Kelvin') disp('4.-Reamur') disp('0.- Salir') x=input(''); switch(x) case 1 c=input('ingrese el valor en grados Celcius \n'); f=(9/5)*c+32; k=c+273.15; r=(4/5)*c; case 2 f=input('ingrese el valor en grados Farenheit\n'); c=(f-32)*(5/9) k=c+273.15; r=(4/5)*c;

METODOS NUMERICOS

Stalin Xavier Caza Negrete

end disp('LOS VALORES OBTENIDOS SON') disp('Grados Celcius') disp(c) disp('Grados Farenheit') disp(f) disp('Grados Kelvin') disp(k) disp('Grados Reamur') disp(r)

case 3 k=input('ingrese el valor en grados Kelvin\n'); c=k-273.15; f=(9/5)*c+32; r=(4/5)*c; case 4 r=input('ingrese el valor en grados Reamur\n'); c=r*(5/4); f=(9/5)*c+32; k=c+273.15; case 0 return;

USO DE LA FUNCION EN MATLAB

ESCUELA POLITECNICA DEL EJERCITO DEBER DE METODOS NUMERICOS --------------------------------------------------------------------SEGUNDO EJERCICIO Programa para convertir unidades de temperatura --------------------------------------------------------------------Seleccione la escala desde la cual se transformara 1.-Celsius 2.-Farenheit 3.-Kelvin 4.-Reamur 0.- Salir 4 ingrese el valor en grados Reamur 4 LOS VALORES OBTENIDOS SON Grados Celcius 5 Grados Farenheit 41 Grados Kelvin 278.1500 Grados Reamur 4

METODOS NUMERICOS

Stalin Xavier Caza Negrete

3. Crear una funcin M-le con la cual se graque la siguiente funcin:


x(t) = (R r)5sin(t) rsin( Rr t) r y (t) =
r t) (R r)sin(t) rsin( R r

z (t) =

PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

function [ ] = grafun3( R,r,a,b,n ) %ingrese valores de R,r el intervalo y numeros de puntos a dibujar. % de la forma: grafica5( R,r,a,b,n ) t = linspace(a,b,n); if(r)==0 disp('Ingrese otro valor de r, y que no se puede dividir para cero') else plot(((R-r).*5.*sin(t)-r.*sin(((R-r)./(r)).*t)),((R-r).*sin(t) -r.*sin(((R-r)./(r)).*t)),'g'); grid on; title('Grafica De La Funcion Paramtrica'); xlabel('(R-r)5sin(t)-rsin((R-r)/(r)*t)'); ylabel('(R-r)sin(t)-rsin((R-r)/(r)*t)'); end end

USO DE LA FUNCION EN MATLAB

>> grafun3(25,26,-10,10,5000)

METODOS NUMERICOS

Stalin Xavier Caza Negrete

4. Escribir una funcin (M-le), llamada simpar(j), que realice lo siguiente: la suma de cuadrados de todos los nmeros enteros impares menores o iguales a n.
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

function [ ] = simpar( n) %ingrese un numero n %se realizara la suma de los cuadrados de %todos los enteros impares menores %o iguales al valor ingresado suma=0; for i=1:2:n suma=suma+(i^2); end disp('La suma total es') disp(suma) end
USO DE LA FUNCION EN MATLAB

>> simpar(3) La suma total es 10

5. Desarrolle un cdigo que permita dibujar un crculo con centro (x0,y0,r). Sugerencia: Utilice la ecuacin paramtrica del crculo
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

function [ ] =grafcir( x,y,r ) %ingrese las coordenadas del centro de la ccircunferencia %y el valor del radio %de la forma: grafcir(absisa,ordenada,radio) t = linspace(0,2.*pi,1000); plot(r.*cos(t)+x,r.*sin(t)+y,'or'); grid on; title('Grafica De La Circunferencia'); xlabel('Eje De Abscisas'); ylabel('Eje De Ordenadas'); end

METODOS NUMERICOS
USO DE LA FUNCION EN MATLAB

Stalin Xavier Caza Negrete

>> grafcir(-3,5,4)

6. Diseee un programa para calcular las races de una ecuacin de segundo grado
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

clc; clear all; disp(' ESCUELA POLITECNICA DEL EJERCITO ') disp(' DEBER DE METODOS NUMERICOS') disp('---------------------------------------------------------------------') disp('SEPTIMO EJERCICIO') disp('Programa que permite encontrar ') disp('las raices de una ecuacion cuadratica') disp('---------------------------------------------------------------------') disp('ingrese los coeficientes de la ecuacion') a=input('ingrese el coeficiente del termino cuadrado\n'); b=input('ingrese el coeficinete del siguiente termino\n'); c=input('ingrese el valor del termino independiente\n'); d=b^2-(4*a*c); if(d>0) disp('Existen soluciones reales distintas') disp('') end if(d==0) disp('Existen soluciones reales iguales') disp('') end if(d<0) disp('No existen soluciones reales') disp('') end disp('LAS RAICES DE LA ECUACION SON') R1=(-b+sqrt(d))/(2*a) R2=(-b-sqrt(d))/(2*a)

METODOS NUMERICOS
USO DE LA FUNCION EN MATLAB

Stalin Xavier Caza Negrete

ESCUELA POLITECNICA DEL EJERCITO DEBER DE METODOS NUMERICOS --------------------------------------------------------------------SEPTIMO EJERCICIO Programa que permite encontrar las raices de una ecuacion cuadratica --------------------------------------------------------------------ingrese los coeficientes de la ecuacion ingrese el coeficiente del termino cuadrado 3 ingrese el coeficinete del siguiente termino -2 ingrese el valor del termino independiente 1 No existen soluciones reales LAS RAICES DE LA ECUACION SON R1 = 0.3333 + 0.4714i R2 = 0.3333 - 0.4714i

7. Desarrollar un programa que permita calcular las notas nales de los estudiantes con tres notas parciales, quin pasa de 21 escribe 1 y si no 0.
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

clc; clear all; disp(' ESCUELA POLITECNICA DEL EJERCITO ') disp(' DEBER DE METODOS NUMERICOS') disp('---------------------------------------------------------------------') disp('OCTAVO EJERCICIO') disp('NOTAS FINALES') disp(' calcula la nota final de los estudiantes') disp(' ingresando tres notas parciales') disp('---------------------------------------------------------------------') t=1; while t~=0; disp('SELECCIONE UNA OPCION') p=input('1).INGRESAR CALIFICACIONES \n0).SALIR DEL PROGRAMA \n'); switch p case 1 a=input('Ingrese la primera nota del estudiante \n entre 0 y 20 \n'); if a<0||a>20 a=input('Ingrese nuevamente la primera nota \n'); end b=input('Ingrese la segunda nota del estudiante \n entre 0 y 20 \n'); if b<0||a>20 b=input('Ingrese nuevamente segunda la nota \n'); end c=input('Ingrese la tercera nota del estudiante \n entre 0 y 20 \n'); if c<0||a>20 c=input('Ingrese nuevamente tercera la nota \n'); end sum=(a+b+c)/3; if sum>=21 nota=sum

METODOS NUMERICOS
disp('1') end if sum<21 nota=sum disp('0') end case 0 t=0; otherwise p=0; end end
USO DE LA FUNCION EN MATLAB

Stalin Xavier Caza Negrete

ESCUELA POLITECNICA DEL EJERCITO DEBER DE METODOS NUMERICOS --------------------------------------------------------------------OCTAVO EJERCICIO NOTAS FINALES calcula la nota final de los estudiantes ingresando tres notas parciales --------------------------------------------------------------------SELECCIONE UNA OPCION 1).INGRESAR CALIFICACIONES 0).SALIR DEL PROGRAMA 1 Ingrese la primera nota del estudiante entre 0 y 20 25 Ingrese nuevamente la primera nota17 Ingrese la segunda nota del estudiante entre 0 y 20 20 Ingrese la tercera nota del estudiante entre 0 y 20 03 nota = 13.3333 0 SELECCIONE UNA OPCION 1).INGRESAR CALIFICACIONES 0).SALIR DEL PROGRAMA 0

8. Programa para calcular la raz n - sima de una funcinf (x) = xN A, cuyas races reales vienen dadas por Pk =
(N 1) Pk + N
A 1 pN k1

PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

clc; clear all; disp(' ESCUELA POLITECNICA DEL EJERCITO ') disp(' DEBER DE METODOS NUMERICOS') disp('---------------------------------------------------------------------') disp('NOVENO EJERCICIO') disp('Raiz N-ESIMA de f(x)=x^N-A')

METODOS NUMERICOS

Stalin Xavier Caza Negrete

disp('---------------------------------------------------------------------') A=input('INGRESE EL VALOR DE A \n'); N=input('INGRESE EL VALOR DE N \n'); x=0; x=A^(1/N); P(1)=x; P(2)=((N-1)*P(1)+(A/(P(1))^(N-1)))/N; disp('EL VALOR DE LA RAIZ ES') disp(P(2))
USO DE LA FUNCION EN MATLAB

ESCUELA POLITECNICA DEL EJERCITO DEBER DE METODOS NUMERICOS --------------------------------------------------------------------NOVENO EJERCICIO Raiz N-ESIMA de f(x)=x^N-A --------------------------------------------------------------------INGRESE EL VALOR DE A 5 INGRESE EL VALOR DE N -3 EL VALOR DE LA RAIZ ES 0.5848

9. Construir una funcin que calcule el n-esimo termino de la serie denida por Un = con Uo = 1 .
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

Un1 + 2

function [ A] = terminoUN( n ) %Construir una funcion que calcule el %n-esimo termino de la serie definida por Un=sqrt(Un_1+2) %se lo utiliza de la forma: terminoUN( n ) donde n es un numer entero %el cual queremos saber en la serie A=1; p=1; for i=1:1:n A=sqrt(p+2); p=A; end A; end

USO DE LA FUNCION EN MATLAB

>> terminoUN(0) ans = 1 >> terminoUN(2) ans = 1.9319 >> terminoUN(20) ans = 2.0000

10

METODOS NUMERICOS

Stalin Xavier Caza Negrete

10. Escriba un programa que dibuje un cuadrado de nxn asteriscos. El valor del entero n es el argumento de entrada.
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

clc; clear all; disp(' ESCUELA POLITECNICA DEL EJERCITO ') disp(' DEBER DE METODOS NUMERICOS') disp('---------------------------------------------------------------------') disp('DECIMO PRIMER EJERCICIO') disp('Programa para dibujar un cuadrado de nxn asteriscos') disp('---------------------------------------------------------------------') n=input('ingrese el numero de asteriscos que debe tener el lado del cuadrado \n'); for i=1:n for j=1:n a(i,j)=('*'); end end a
USO DE LA FUNCION EN MATLAB

ESCUELA POLITECNICA DEL EJERCITO DEBER DE METODOS NUMERICOS --------------------------------------------------------------------DECIMO PRIMER EJERCICIO Programa para dibujar un cuadrado de nxn asteriscos --------------------------------------------------------------------ingrese el numero de asteriscos que debe tener el lado del cuadrado 4 a = **** **** **** ****

11. Escriba una funcin que imprima la suma de los cuadrados de los nmeros enteros comprendidos en un intervalo dado como argumentos
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

function [ ] = sumcuad( a,b) %ingrese un intervalo [a , b] %se realizara la suma de los cuadrados de %todos los enteros comprendidos %dentro del intervalo suma=0; while(b<a) b=input('ingrese un valor de mayor al primero \n') end

11

METODOS NUMERICOS
for i=a:1:b suma=suma+(i^2); end disp('La suma total es') disp(suma) end
USO DE LA FUNCION EN MATLAB

Stalin Xavier Caza Negrete

>> sumcuad(-1,4) La suma total es 31

12. Recibimos de las distintas sucursales de la empresa los datos correspondientes a las ventas en dolares de cada vendedor en los distintos trimestres del aos, como se indica en la tabla adjunta Vendedor Trimestre 1 Trimestre 2 Trimestre 3 Trimestre 4 Miguel Garca 1500000 2000000 1850000 2100000 Ral Racines 1200000 1340000 1750000 1800000 Elena Casas 1460000 1700000 1900000 2000000 Javier Martin 1100000 1600000 1640000 1700000

a) b)

Crear una matriz con los datos de la tabla Se pide crear una funcin venta total que permita calcular: 1) Las ventas totales por trimestres 2) Ventas totales por vendedor

c) d)

Crear una funcin promedio, el promedio de ventas por trimestre Cul es el vendedor que tiene menor venta en el tercer trimestre

PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

------------------PROGRAMA PRINCIPAL-----------------------------clc; clear all; disp(' ESCUELA POLITECNICA DEL EJERCITO ') disp(' DEBER DE METODOS NUMERICOS')

12

METODOS NUMERICOS

Stalin Xavier Caza Negrete

disp('---------------------------------------------------------------------') disp('DECIMO SEGUNDO EJERCICIO') disp('Programa que calcula datos de la empresa') disp('---------------------------------------------------------------------') Miguel=[1500000 2000000 1850000 2100000]; Raul=[1200000 1340000 1750000 1800000]; Elena=[1460000 1700000 1900000 2000000]; Javier=[1100000 1600000 1640000 1700000]; disp('MATRIZ DE LOS DATOS DE LA TABLA') Datos=[Miguel;Raul;Elena;Javier] disp('VENTAS POR TRIMESTRE Y POR VENDEDOR') ventatotal(Datos); disp('PROMEDIO POR TRIMESTRE') promedio(ans) disp('VENTAS POR TRIMESTRE Y POR VENDEDOR') disp(Datos(4,3)) ------------------FUNCIONVENTATOTAL-----------------------------function [ Trimestre ] = ventatotal(A) %Permita calcular %Las ventas totales por trimestres %Vental totales por vendedor p=0; q=0; m=0; for i=1:1:4 for j=1:1:4 p=p+A(j,i); q=q+A(i,j); m=m+1; if (m==4) T1=p; E1=q; end if (m==8) T2=p-T1; E2=q-E1; end if (m==12) T3=p-T1-T2; E3=q-E1-E2; end if (m==16) T4=p-T1-T2-T3; E4=q-E1-E2-E3; end end end Trimestre=[T1 T2 T3 T4] Empleados=[E1; E2; E3; E4] end ------------------FUNCIONPROMEDIO----------------------------function [ ] = promedio( A) %Promedio de ventas por trimestre % for i=1:1:4 P(i)=A(i)/4; end disp('Prom =') disp(P) end

13

METODOS NUMERICOS
USO DE LA FUNCION EN MATLAB

Stalin Xavier Caza Negrete

ESCUELA POLITECNICA DEL EJERCITO DEBER DE METODOS NUMERICOS --------------------------------------------------------------------DECIMO SEGUNDO EJERCICIO Programa que calcula datos de la empresa --------------------------------------------------------------------MATRIZ DE LOS DATOS DE LA TABLA Datos = 1500000 2000000 1850000 2100000 1200000 1340000 1750000 1800000 1460000 1700000 1900000 2000000 1100000 1600000 1640000 1700000 VENTAS POR TRIMESTRE Y POR VENDEDOR Trimestre = 5260000 6640000 7140000 7600000 Empleados = 7450000 6090000 7060000 6040000 PROMEDIO POR TRIMESTRE Prom = 1315000 1660000 1785000 1900000 VENTAS POR TRIMESTRE Y POR VENDEDOR 1640000

13. Escribir un programa que exprese en horas, minutos y segundos un tiempo expresado en segundos. Sugerencia: Consulte la instruccin oor
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

clc; clear all; disp(' ESCUELA POLITECNICA DEL EJERCITO ') disp(' DEBER DE METODOS NUMERICOS') disp('---------------------------------------------------------------------') disp('DECIMO TERCER EJERCICIO') disp('Programa expresa en horas, minutos y segundos') disp('un valor ingresado en segundos') disp('---------------------------------------------------------------------') s=input('Ingrese el valor en segundos \n'); h=floor(s/3600); if mod(s,3600)>0 min=floor(mod(s,3600)/60); seg=mod(mod(s,3600),60); end disp('El numero ingresado equivale a') disp('horas ') disp(h) disp('minutos') disp(min)

14

METODOS NUMERICOS
disp('segundos') disp(seg)
USO DE LA FUNCION EN MATLAB

Stalin Xavier Caza Negrete

ESCUELA POLITECNICA DEL EJERCITO DEBER DE METODOS NUMERICOS --------------------------------------------------------------------DECIMO TERCER EJERCICIO Programa expresa en horas, minutos y segundos un valor ingresado en segundos --------------------------------------------------------------------Ingrese el valor en segundos 6652 El numero ingresado equivale a horas 1 minutos 50 segundos 52

14. Con la ayuda de la funcin max, escriba un programa que imprima los dos primeros nmeros ms grandes dentro de un vector.
PROGRAMACION EN EDITOR DE TEXTO DE MATLAB

clc; clear all; disp(' ESCUELA POLITECNICA DEL EJERCITO ') disp(' DEBER DE METODOS NUMERICOS') disp('---------------------------------------------------------------------') disp('DECIMOCUARTO EJERCICIO') disp('Programa para encontrar valores maximo de un vector') disp('---------------------------------------------------------------------') A=input('ingrese el vector\n') [M1,y]=max(A); A(y)=0; M2=max(A); disp('LOS VALORES MAXIMOS SON') M1 M2
USO DE LA FUNCION EN MATLAB

ESCUELA POLITECNICA DEL EJERCITO DEBER DE METODOS NUMERICOS --------------------------------------------------------------------DECIMOCUARTO EJERCICIO Programa para encontrar valores maximo de un vector ---------------------------------------------------------------------

15

METODOS NUMERICOS
ingrese el vector [65 76 76 87 98 34] A = 65 76 76 87 LOS VALORES MAXIMOS SON M1 = 98 M2 = 87

Stalin Xavier Caza Negrete

98

34

15. Utlizando los desarrollos de Taylor para las funciones seno, coseno, exponencialex ,
ln(1 + x), arctan(x), construya funciones (M.le) que calculen su valor para dife-

rentes valores de truncamiento. Presente estos datos en una tabla


SENO(X)

function [ ] = seno(a,t ) %Permite verificar la proximidad en los resultados % de acuerdo al valor de truncamiento %a = valor de trucamiento %t es valor que necesitamos conocer de la funcion syms x ; m=0; n=0; for i=0:1:a; n = n+ ((-1)^i)*((x)^(2*i+1))/factorial(2*i+1); end fprintf('Trunc\t\tValor\n') for i=0:1:a; m = m+ ((-1)^i)*((x)^(2*i+1))/factorial(2*i+1); x=t; fprintf('%d\t\t%f\n',i,eval(m)) end fprintf('\n') disp('SERIE DE TAYLOR DESARROLLADA') disp('CORRESPONDIENTE A LA FUNCION') disp(n) disp('SE CALCULARA EL VALOR DE LA FUNCION CON EL VALOR DE:') x=t; disp(x) disp('El RESULTADO DE ACUERDO AL TRUNCAMIENTO ES') Q=eval(m); disp(Q) end
USO DE LA FUNCION EN MATLAB

>> seno(6,pi/2) Trunc Valor 0 1.570796 1 0.924832 2 1.004525

16

METODOS NUMERICOS
3 0.999843 4 1.000004 5 1.000000 6 1.000000 SERIE DE TAYLOR CORRESPONDIENTE x^13/6227020800 x^5/120 - x^3/6 SE CALCULARA EL 1.5708 El RESULTADO DE 1.0000

Stalin Xavier Caza Negrete

DESARROLLADA A LA FUNCION - x^11/39916800 + x^9/362880 - x^7/5040 + + x VALOR DE LA FUNCION CON EL VALOR DE: ACUERDO AL TRUNCAMIENTO ES

coseno(x)

function [ ] = coseno(a,t ) %Permite verificar la proximidad en los resultados % de acuerdo al valor de truncamiento %a = valor de trucamiento %t es valor que necesitamos conocer de la funcion syms x ; m=0; n=0; for i=0:1:a; n = n+ (-1)^i*((x)^(2*i))/factorial(2*i); end fprintf('Trunc\t\tValor\n') for i=0:1:a; m = m+ (-1)^i*((x)^(2*i))/factorial(2*i); x=t; fprintf('%d\t\t%f\n',i,eval(m)) end fprintf('\n') disp('SERIE DE TAYLOR DESARROLLADA') disp('CORRESPONDIENTE A LA FUNCION') disp(n) disp('SE CALCULARA EL VALOR DE LA FUNCION CON EL VALOR DE:') x=t; disp(x) disp('El RESULTADO DE ACUERDO AL TRUNCAMIENTO ES') Q=eval(m); disp(Q) end
USO DE LA FUNCION EN MATLAB

>> coseno(6,pi) Trunc Valor 0 1.000000 1 -3.934802 2 0.123910 3 -1.211353 4 -0.976022 5 -1.001829 6 -0.999900 SERIE DE TAYLOR DESARROLLADA CORRESPONDIENTE A LA FUNCION x^12/479001600 - x^10/3628800 + x^8/40320 - x^6/720 + x^4/24 -

17

METODOS NUMERICOS

Stalin Xavier Caza Negrete

x^2/2 + 1 SE CALCULARA EL VALOR DE LA FUNCION CON EL VALOR DE: 3.1416 El RESULTADO DE ACUERDO AL TRUNCAMIENTO ES -0.9999
EXPONENCIAL ex

function [ ] = exponencial(a,t ) %Permite verificar la proximidad en los resultados % de acuerdo al valor de truncamiento %a = valor de trucamiento %t es valor que necesitamos conocer de la funcion syms x ; m=0; n=0; for i=0:1:a; n = n+ (x^(i))/factorial(i); end fprintf('Trunc\t\tValor\n') for i=0:1:a; m = m+ (x^(i))/factorial(i); x=t; fprintf('%d\t\t%f\n',i,eval(m)) end fprintf('\n') disp('SERIE DE TAYLOR DESARROLLADA') disp('CORRESPONDIENTE A LA FUNCION') disp(n) disp('SE CALCULARA EL VALOR DE LA FUNCION CON EL VALOR DE:') x=t; disp(x) disp('El RESULTADO DE ACUERDO AL TRUNCAMIENTO ES') Q=eval(m); disp(Q) end
USO DE LA FUNCION EN MATLAB

>> exponencial(10,6) Trunc Valor 0 1.000000 1 7.000000 2 25.000000 3 61.000000 4 115.000000 5 179.800000 6 244.600000 7 300.142857 8 341.800000 9 369.571429 10 386.234286 SERIE DE TAYLOR DESARROLLADA CORRESPONDIENTE A LA FUNCION x^10/3628800 + x^9/362880 + x^8/40320 + x^7/5040 + x^6/720 + x^5/120 + x^4/24 + x^3/6 + x^2/2 + x + 1

18

METODOS NUMERICOS

Stalin Xavier Caza Negrete

SE CALCULARA EL VALOR DE LA FUNCION CON EL VALOR DE: 6 El RESULTADO DE ACUERDO AL TRUNCAMIENTO ES 386.2343

LOGARITMICA Ln(1 + x)

function [ ] = logaritmica(a,t ) %Permite verificar la proximidad en los resultados % de acuerdo al valor de truncamiento %a = valor de trucamiento %t es valor que necesitamos conocer de la funcion while t<=0|t>=1 t=input('Ingrese un valor entre 0 y 1 \n') end syms x ; m=0; n=0; for i=0:1:a; n = n+ (x^(i+1))/(i+1); end fprintf('Trunc\t\tValor\n') for i=0:1:a; m = m+ (x^(i+1))/(i+1); x=t; fprintf('%d\t\t%f\n',i,eval(m)) end fprintf('\n') disp('SERIE DE TAYLOR DESARROLLADA') disp('CORRESPONDIENTE A LA FUNCION') disp(n) disp('SE CALCULARA EL VALOR DE LA FUNCION CON EL VALOR DE:') x=t; disp(x) disp('El RESULTADO DE ACUERDO AL TRUNCAMIENTO ES') Q=eval(m); disp(Q) end
USO DE LA FUNCION EN MATLAB

>> logaritmica(6,0.3) Trunc Valor 0 0.300000 1 0.345000 2 0.354000 3 0.356025 4 0.356511 5 0.356633 6 0.356664 SERIE DE TAYLOR DESARROLLADA CORRESPONDIENTE A LA FUNCION x^7/7 + x^6/6 + x^5/5 + x^4/4 + x^3/3 + x^2/2 + x

19

METODOS NUMERICOS

Stalin Xavier Caza Negrete

SE CALCULARA EL VALOR DE LA FUNCION CON EL VALOR DE: 0.3000 El RESULTADO DE ACUERDO AL TRUNCAMIENTO ES 0.3567

ARCOTANGENTE(x)

function [ ] = arctangente(a,t ) %Permite verificar la proximidad en los resultados % de acuerdo al valor de truncamiento %a = valor de trucamiento %t es valor que necesitamos conocer de la funcion while t<=0|t>=1 t=input('Ingrese un valor entre 0 y 1 \n'); end syms x ; m=0; n=0; for i=0:1:a; n = n+ ((-1)^i)*(x^(2*i+1))/(2*i+1); end fprintf('Trunc\t\tValor\n') for i=0:1:a; m = m+ ((-1)^i)*(x^(2*i+1))/(2*i+1); x=t; fprintf('%d\t\t%f\n',i,eval(m)) end fprintf('\n') disp('SERIE DE TAYLOR DESARROLLADA') disp('CORRESPONDIENTE A LA FUNCION') disp(n) disp('SE CALCULARA EL VALOR DE LA FUNCION CON EL VALOR DE:') x=t; disp(x) disp('El RESULTADO DE ACUERDO AL TRUNCAMIENTO ES') Q=eval(m); disp(Q) end
USO DE LA FUNCION EN MATLAB

>> arctangente(6,0.35) Trunc Valor 0 0.350000 1 0.335708 2 0.336759 3 0.336667 4 0.336676 5 0.336675 6 0.336675 SERIE DE TAYLOR DESARROLLADA CORRESPONDIENTE A LA FUNCION x^13/13 - x^11/11 + x^9/9 - x^7/7 + x^5/5 - x^3/3 + x SE CALCULARA EL VALOR DE LA FUNCION CON EL VALOR DE:

20

METODOS NUMERICOS
0.3500 El RESULTADO DE ACUERDO AL TRUNCAMIENTO ES 0.3367

Stalin Xavier Caza Negrete

16. En cada uno de los siguientes casos, halle el error absoluto y relativo y determine el nmero de cifras signicativas de la aproximacin.

a)

x = 2,71828182 , x = 2,7182

Error Absoluto
A

= |x x | = |2,71828182 2,7182| = 8,1820 105

Error Relativo
R

10d |x x | < |x| 2 |2,71828182 2,7182| 10d = < |2,71828182| 2 d 10 = 3,0100 105 < 2 104 = 3,0100 105 < 2 =

d=4

b)

y = 98350 , y = 98000

Error Absoluto
A

= |x x | = |98350 98000| = 350

Error Relativo 21

METODOS NUMERICOS
|x x | 10d < |x| 2 |98350 98000| 10d = < |98350| 2 d 10 = 0,0036 < 2 102 = 0,0036 < 2 =

Stalin Xavier Caza Negrete

d=2

c)

z = 0,000068 , z = 0,00006

Error Absoluto
A

= |x x | = |0,000068 0,00006| = 8,000 106

Error Relativo
R

10d |x x | < |x| 2 10d |0,000068 0,00006| < = |0,000068| 2 d 10 = 0,1176 < 2 100 = 0,1176 < 2 =

d=0

22

METODOS NUMERICOS 17. Complete el siguiente clculo:


1 4

Stalin Xavier Caza Negrete

e dx =
0 0

x2

1 4

(1 + x2 +

x4 x6 + )dx = p 2! 3!

Determine que tipo de error se presenta en esta situacin y compare su resultado con el valor exacto p = 0,2553074606
1 4

ex dx = |x +
2

0
1 4

x3 x5 x7 0,25 + + | 3 10 42 0

ex dx = (2,339 + 106 ) (0,255307) ex dx = 0,255304661


2

0
1 4

Se presenta un error de trucamiento en la parte de la serie correspondiente a exp(x2 ) ademas por dicho error se nota una variacion a partir del sexto digito decimal al lado derecho de la coma. Error Absoluto
A

= |x x | = |0,2553074606 0,255304661| = 2,7996 106

Error Relativo
R

= =

|x x | 10d < |x| 2

|0,2553074606 0,255304661| 10d < |0,2553074606| 2 4 10 = 1,0966 105 < 2

d = 4 Es el numero de cifras signicativas

23

METODOS NUMERICOS 18. Dados los desarrollos de Taylor

Stalin Xavier Caza Negrete

h2 h3 h4 exp(h) = 1 + h + + + + O(h5 ) 2! 3! 4!

y
h3 sen(h) = h + O(h5 ) 3!

Determinar el orden de aproximacion de su suma y de su producto.


APROXIMACION DE SUMA

h2 h3 h4 h3 5 exp(h) + sen(h) = 1 + h + + + + O(h ) + h + O(h5 ) 2! 3! 4! 3! 2 4 h h exp(h) + sen(h) = 1 + 2h + + + O(h5 ) 2! 4!

El orden de aproximacin es 5
APROXIMACION DE PRODUCTO

exp(h) sen(h) = (1 + h +

h2 h3 h4 h3 + + + O(h5 )) (h + O(h5 )) 2! 3! 4! 3!

exp(h) sen(h) = h

h3 h4 h5 h4 h6 h5 h7 + h2 + + 3! 3! 2! 3! 3! 3! 3! 4! 4! 3!

+O(h5 ) + O(h5 ) + O(h5 ) O(h5 ) exp(h) sen(h) = h + h2 h3 h5 h5 h6 h7 + + O(h10 ) + O(h5 ) 3! 2! 3! 4! 3! 3! 4! 3! h3 + O(h5 ) 3!

exp(h) sen(h) = h + h2

El orden de aproximacin es 5

24

METODOS NUMERICOS 19. Dados los desarrollos de Taylor


h2 h4 + + O(h6 ) 2! 4! h3 h5 sen(h) = h + + O(h7 ) 3! 5! cos(h) = 1

Stalin Xavier Caza Negrete

Determine el orden de aproximacion de suma y de producto


APROXIMACION DE SUMA

cos(h) + sen(h) = 1

h3 h5 h2 h4 + + O(h6 ) + h + + O(h7 ) 2! 4! 3! 5! h2 h3 h4 h5 cos(h) + sen(h) = 1 + h + + + O(h6 ) 2! 3! 4! 5!


APROXIMACION DE PRODUCTO

h2 h4 h3 h5 6 cos(h) sen(h) = (1 + + O(h )) (h + + O(h7 )) 2! 4! 3! 5! 3 3 5 5 5 h h h h h h7 cos(h) sen(h) = h + + 2! 3! 5! 2! 3! 4! 5! 2! h9 h7 + + O(h6 ) + O(h13 ) 4! 3! 5! 4! cos(h) sen(h) = h h3 h3 h5 h5 h5 + + + O(h6 ) 2! 3! 5! 2! 3! 4! 3 5 5h 4h cos(h) sen(h) = h + O(h6 ) 3! 5!

25

METODOS NUMERICOS

Stalin Xavier Caza Negrete

20. La formula mejorada para la resolucion de la ecuacin de segundo grado. Supongamos que a = 0 y que b2 4ac > 0 y consideremos la ecuacion ax2 + bx + c = 0. Sus raices pueden hallarse mediante la cnocida formula
x1 = b + b2 4ac b b2 4ac y x2 = 2a 2a

Pruebe que estas raices pueden calcularse mediante las formulas equivalentes
x1 = 2c 2c y x2 = 2 b + b 4ac b b2 4ac b 4ac, hay que

Indicacion.Racionalice el numerador de las primeras. Cuando |b|

proceder con cuidado para evitar la perdida de precision por cancelacion. Si b > 0, entonces x1 debera ser calculado con las formulas y x2 deberia ser calculada con la primera formula, mientras que si b < 0, entonces x1 deberia ser calculado usando (i) y x2 deberia ser calculadousando(ii).
x1 = x1 = x1 = x1 = x2 = b + b2 4ac b + b2 4ac 2a b + b2 4ac b2 4ac b2 2a (b + b2 4ac) 4ac 2a (b + b2 4ac) 2c b + b2 4ac 2c b b2 4ac

b + b2 4ac 2c x2 = b b2 4ac b + b2 4ac 2c(b + b2 4ac) x2 = b2 b2 + 4ac 2c(b + b2 4ac) x2 = 4ac

26

METODOS NUMERICOS
b2 4ac) 2a b b2 4ac) x2 = 2a (b +

Stalin Xavier Caza Negrete

x2 =

21. Use la formula adecuda para calcular x1 y x2 , tal como se explica en el ejercicio anterior, para hallar las raices de las siguientes ecuaciones de segundo grado

a)

x2 1000,001x + 1

Como b > 0 entonces se utiliza:


x1 = b + b2 4ac 2a

x2 =

2c b b2 4ac

x1 = 1000

x2 = 0,001

b)

x2 10000,0001x + 1

Como b > 0 entonces se utiliza:


x1 = b + b2 4ac 2a

x2 =

2c b b2 4ac

x1 = 10000

x2 = 0,0001

c)

x2 100000,00001x + 1

Como b > 0 entonces se utiliza:


x1 = b + b2 4ac 2a

x2 =

2c b b2 4ac

x1 = 10000

x2 = 0,00001

d)

x2 1000000,000001x + 1

Como b > 0 entonces se utiliza:


x1 = b + b2 4ac 2a

x2 =

2c b b2 4ac

x1 = 1000000

x2 = 0,000001

27

Vous aimerez peut-être aussi