Title | Metodo de trapecio en Matlab |
---|---|
Author | Leonardo Gonzalez |
Course | Aplicación de las leyes de conservación en sistemas ingenieriles |
Institution | Instituto Tecnológico y de Estudios Superiores de Monterrey |
Pages | 13 |
File Size | 660.9 KB |
File Type | |
Total Downloads | 81 |
Total Views | 134 |
Metodo de trapecio en Matlab con graficas _________...
Integración numérica - Rectángulo Leoanardo González A01709435 El objetiv0 es resolver integrales con métodos numéricos. En integración numérica el dominio
se discretiza
en n segmentos, y la operación de la integral se convierte en una suma:
Veamos por ejemplo la solución de la integral:
Que tiene solución exacta:
Comencemos con el método del rectángulo. Primero definimos la función y los límites de integración: f =@(x) 12 + 2 * sin(x) - x.^2 / 10; a = -10; b = 10; Podemos comenzar por la solución de esta integral usando MATLAB Ia = integral(f,a,b) Ia = 173.3333
La solución con el método del rectángulo comienza por definir el tamaño del paso que queremos utilizar para resolver el problema. $\Delta x=0.5$ dx = 2; x = a:dx:b; y = f(x); Veamos la integral gráficamente: fplot(f,[a,b]); hold on; stairs(x,y,'r');
stem(x,y, 'r.'); hold off;
1
Ahora calculemos la solución numérica con el método del rectángulo: N = length(x); In = 0; for k = 1:N-1 In = In + dx * y(k); end disp([Ia, In, N]) 173.3333
174.1761
11.0000
Problema 1
f =@(x) x.^3; a = 0; b = 1; Ia = integral(f,a,b); dx = 0.01; x = a:dx:b; y = f(x); fplot(f,[a,b]); hold on; stairs(x,y,'r');
stem(x,y, 'r.'); hold off;
2
N = length(x); In = 0; for k = 1:N-1 In = In + dx * y(k); end disp([Ia, In, N]) 0.2500
0.2450
101.0000
Problema 2
f =@(x) 3 * x.^3 - x.^2 + x - 1; a = 2; b = 3; Ia = integral(f,a,b); dx = 0.1; x = a:dx:b; y = f(x); fplot(f,[a,b]); hold on; stairs(x,y,'r'); stem(x,y, 'r.'); hold off;
3
N = length(x); In = 0; for k = 1:N-1 In = In + dx * y(k); end disp([Ia, In, N]) 43.9167
41.3025
11.0000
Problema 3
f =@(x) x./ (x.^2 - 1); a = 2; b = 3; Ia = integral(f,a,b); dx = 0.1; x = a:dx:b; y = f(x); fplot(f,[a,b]); hold on; stairs(x,y,'r');
stem(x,y, 'r.'); hold off;
4
N = length(x); In = 0; for k = 1:N-1 In = In + dx * y(k); end disp([Ia, In, N]) 0.4904
0.5053
11.0000
Problema 4
f =@(x) (sin(x)).^3 .* (cos(x)).^4; a = 0; b = pi / 2; Ia = integral(f,a,b); dx = 0.1; x = a:dx:b; y = f(x); fplot(f,[a,b]); hold on; stairs(x,y,'r'); stem(x,y, 'r.'); hold off;
5
N = length(x); In = 0; for k = 1:N-1 In = In + dx * y(k); end disp([Ia, In, N]) 0.0571
0.0571
16.0000
Problema 5
f =@(x) x.^2 .* log(x); a = 1; b = 5; Ia = integral(f,a,b); dx = 0.1; x = a:dx:b; y = f(x); fplot(f,[a,b]); hold on; stairs(x,y,'r');
stem(x,y, 'r.'); hold off;
6
N = length(x); In = 0; for k = 1:N-1 In = In + dx * y(k); end disp([Ia, In, N]) 53.2821
51.2871
41.0000
Integración numérica - Trapecio En el método del trapecio, la integral se aproxima con la regla:
Si repetimos con el ejemplo anterior:
Primero definimos la función y los límites f =@(x) 12 + 2 * sin(x) - x.^2 / 10; a = -10; b = 10; Ia = integral(f,a,b); dx = 2; x = a:dx:b; 7
y= f(x); fplot(f, [a, b]); hold on; plot(x,y,'r'); stem(x,y,'r.'); hold off;
N = length(x); In = y(1) + y(N); for k = 2:N-1 In = In + 2 * y(k); end In = dx / 2 * In; disp([Ia In N]) 173.3333
172.0000
11.0000
Problema 1
f =@(x) x.^3; a = 0; b = 1; Ia = integral(f,a,b); dx = 0.1; x = a:dx:b; y= f(x); fplot(f, [a, b]); hold on; plot(x,y,'r'); stem(x,y,'r.'); hold off;
8
N = length(x); In = y(1) + y(N); for k = 2:N-1 In = In + 2 * y(k); end In = dx / 2 * In; disp([Ia In N]) 0.2500
0.2525
11.0000
Problema 2
f =@(x) 3 * x.^3 - x.^2 + x - 1; a = 2; b = 3; Ia = integral(f,a,b); dx = 0.1; x = a:dx:b; y= f(x); fplot(f, [a, b]); hold on; plot(x,y,'r'); stem(x,y,'r.'); hold off;
9
N = length(x); In = y(1) + y(N); for k = 2:N-1 In = In + 2 * y(k); end In = dx / 2 * In; disp([Ia In N]) 43.9167
43.9525
11.0000
Problema 3
f =@(x) x./ (x.^2 - 1); a = 2; b = 3; Ia = integral(f,a,b); dx = 0.1; x = a:dx:b; y= f(x); fplot(f, [a, b]); hold on; plot(x,y,'r'); stem(x,y,'r.'); hold off;
10
N = length(x); In = y(1) + y(N); for k = 2:N-1 In = In + 2 * y(k); end In = dx / 2 * In; disp([Ia In N]) 0.4904
0.4907
11.0000
Problema 4
f =@(x) (sin(x)).^3 .* (cos(x)).^4; a = 0; b = pi / 2; Ia = integral(f,a,b); dx = 0.1; x = a:dx:b; y= f(x); fplot(f, [a, b]); hold on; plot(x,y,'r'); stem(x,y,'r.'); hold off;
11
N = length(x); In = y(1) + y(N); for k = 2:N-1 In = In + 2 * y(k); end In = dx / 2 * In; disp([Ia In N]) 0.0571
0.0571
16.0000
Problema 5
f =@(x) x.^2 .* log(x); a = 1; b = 5; Ia = integral(f,a,b); dx = 0.1; x = a:dx:b; y= f(x); fplot(f, [a, b]); hold on; plot(x,y,'r'); stem(x,y,'r.'); hold off;
12
N = length(x); In = y(1) + y(N); for k = 2:N-1 In = In + 2 * y(k); end In = dx / 2 * In; disp([Ia In N]) 53.2821
53.2989
41.0000
13...