Metodos Num ricos 02 0
Transcript of Metodos Num ricos 02 0
![Page 2: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/2.jpg)
Métodos Numéricos con Métodos Numéricos con MATLABMATLAB
Lic. Guillermo Mario Chuquipoma PachecoLic. Guillermo Mario Chuquipoma Pacheco 20102010
![Page 3: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/3.jpg)
Aprendamos
-Crear funciones en el MatLab
MatLap
-Crear funciones en el MatLab
- Plotear funciones en 2D
![Page 4: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/4.jpg)
Crear funciones en el MatLab
![Page 5: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/5.jpg)
Ejercicio 01 .
Crear un archivo m-file en el MatLab de la función:
f : →ℝ ℝ
y f(x)=
Por ejemplo:3f(x) 2x 5= +
Calcular los valores de:
a) f(0) b) f(2) c) f(7) d) f(-2)
Por ejemplo:
![Page 6: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/6.jpg)
Solución:1er paso: Crear un área de trabajo
•El crear un área de trabajo: una carpeta de trabajo.•Colocar el path para poder utilizar las funciones y programas creados,ingresando a los menus mostrados, para añadir la carpeta al Path.
![Page 7: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/7.jpg)
2do paso:
Ahora se introduce:
function y = f(x)y=2*power(x,3)+5;
Crear ahora un fichero función e variable real de una variable.
Creando un archivo m-file
• Lo salvamos con el nombre def.m en carpeta de trabajo.
![Page 8: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/8.jpg)
Paso 3. En la línea de comandos calcular:
>> f(0)ans =
5>> f(2)ans =
21>> f(7)ans =ans =
691>> f(-2)ans =
-11>>
Continuemos….
![Page 9: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/9.jpg)
21
x 4 ,si x 6
f (x) 3x 5 ,si 0 x 6
0 ,si x 0
+ >= + < ≤ ≤
Por ejemplo
1f : →ℝ ℝ
Ejercicio 02 .
Crear un archivo m-file en el MatLab de la función:
Practicar evaluando la función en la línea de comandos.
a) f1(10) b) f1(2) b) f1(-3)d) f1(0) e) f1(5) f) f1(-10)
![Page 10: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/10.jpg)
function y=f1(x)if x<=0
y=0;else
if x>0 & x<=6y=3*x^2+5;
else
Solución
Crear y grabamos un archivo m-file con el nombre f1.m.
>> f1(2)ans =
17
Evaluando
>> f1(10)ans =
14
elsey=x+4;
endend
>> f1(-3)ans =
0
>> f1(5)ans =
80
>> f1(0)ans =
0
>> f1(-10)ans =
0
![Page 11: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/11.jpg)
Ejercicio 03 .
Crear un archivo m-file en el MatLab de la función:
2g : →ℝ ℝ
y g(x,y)=
3g(x,y) 2x y= −Por ejemplo:
Practicar evaluando la función en la línea de comandos.
a) g(1,2) b) g(0,5) c) g(1,1)
![Page 12: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/12.jpg)
Evaluando:>> g(1,2)
SoluciónSolución
Análogo a lo anterior creamos y grabamos un archivo m-file con el nombre g.m.g.m.
function y = g(x,y)
y=2*x-y^3;
>> g(1,2)ans =
-6>> g(0,5)ans =
-125>> g(1,1)ans =
1>>
![Page 13: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/13.jpg)
Ejercicio 04 .
Crear un archivo m-file en el MatLab de la función:
2 2h : →ℝ ℝ
1 2h(r, ) ( h (r, ), h (r, ) )θ = θ θ
1
2
x h (r, )y h (r, )
= θ= θ
Es decir::
x r cos( )y r sen( )
= θ= θ
Por ejemplo:
Practicar evaluando la función en la línea de comandos.
2
r 1/ 6
=θ = π
a) r 1/ 3
=θ = π
b) r 1/ 2
=θ = π
c) r 50
=θ =
e)r 3/ 4
=θ = π
d)
![Page 14: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/14.jpg)
Solución
Análogo a lo anterior creamos y grabamos un archivo m-file con el nombre h.m..m.
function [x, y]=h(r, theta)x=r*cos(theta);y=r*sin(theta);
Evaluando :
>> [x y]=h(1, pi/6)x=
0.86602540378444y=
0.50000000000000
>> [x y]=h(1, pi/3)x=
0.50000000000000y=
0.86602540378444
>> [x y]=h(3, pi/4)x=
2.12132034355964y=
2.12132034355964
>> [x y]=h(1, pi/2)x=
6.123233995736766e-017y=
1
>> [x y]=h(5, 0)x=
5y=
0
![Page 15: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/15.jpg)
Plotear funciones en 2DPlotear funciones en 2D
y cos(x) x= −
y x=
y cos(x)=
3y 2x 5= +
![Page 16: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/16.jpg)
Ejercicio 05.
Hacer un programa de tareas donde se pueda aplicar la función fCrear un archivo m-file, con el nombre de faplic y escriba los siguiente:
x = linspace(-2,2);fx = f(x);plot(x,fx);xlabel('x (reales)');ylabel('f(x)');grid on;axis([min(x) max(x) -12 22]);
Luego llamar en la línea de comandos con :
>> faplic
![Page 17: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/17.jpg)
Resultado al ejecutar:
![Page 18: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/18.jpg)
Ejercicio 06.
Hacer un programa de tareas donde se pueda aplicar la función fCrear un archivo m-file, con el nombre de faplic2 y escriba los siguiente:
x = linspace(0.0,1.4);plot(x,cos(x),'g-',x,x,'b:',x,cos(x)-x,'r--');xlabel(‘Eje X');ylabel(‘Eje Y');ylabel(‘Eje Y');grid on;axis([min(x) max(x) -1 1.5]);
Luego llamar en la línea de comandos con :
>> faplic2
![Page 19: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/19.jpg)
Resultado al ejecutar:
![Page 20: Metodos Num ricos 02 0](https://reader031.fdocuments.ec/reader031/viewer/2022012409/616a428d11a7b741a3508ff8/html5/thumbnails/20.jpg)
GRACIAS POR SU ATENCIÓNGRACIAS POR SU ATENCIÓN