Buscar

Algoritmo Integral quadratura de gauss


Continue navegando


Prévia do material em texto

Integração numérica – Quadratura de Gauss
function [A1, A2, A3, t1, t2, t3]=quadrat(n)
 if n==2 then
 A1=1.0;
 A2=0.0;
 A3=1.0;
 t1=-0.57735;
 t2=0.0;
 t3=-t1;
 else if n==3 then
 A1=5/9;
 A2=8/9;
 A3=A1;
 t1=-0.7745;
 t2=0.0;
 t3=-t1; 
 end
 end
endfunction
function h=f(t, a, b)
 x=(((b-a)*t)+b+a)/2;
 d=(b-a)/2;
 h=sin(x)*d;
 //h=cos(x)*d
 //h=(%e^x)*d
 //h=(1/(1+x))*d
 //h=(x+x^3)*d
endfunction
ve= //valor analítico
n= //número de pontos 
a= //extremos do intervalo
b=
[A1,A2,A3,t1,t2,t3]=quadrat(n)
I=A1*f(t1,a,b)+A2*f(t2,a,b)+A3*f(t3,a,b)
erro=ve-I
errop=((ve-I)*100)/ve�
�
	[a,b] = [0,1]
	valor exato
	I
	Erro
	Erro Percentual
	f(x)=sen(x)
	0.4596977
	0.4595878 
	0.0001099
	
	f(x)=cos(x)
	0.841471
	0.8412698
	0.0002012
	
	f(x)=e^x
	1.718281828
	1.7178964
	0.0003854
	
	f(x)=1/(1+x)
	0.69314718
	0.6923077
	0.0008395
	
	f(x)=x+x^3
	0.75
	 0.75
	0
	
�
a) f(x)=sen(x)
-->exec('C:\Users\Matheus\Documents\quadrat.sci', -1)
-->exec('C:\Users\Matheus\Documents\funções.sci', -1)
-->ve=0.4596977;
-->n=2;
-->a=0;
-->b=1;
-->[A1,A2,A3,t1,t2,t3]=quadrat(n);
-->I=A1*f(t1,a,b)+A2*f(t2,a,b)+A3*f(t3,a,b)
 I = 0.4595878 
-->erro=ve-I
 erro = 0.0001099 
 
b)f(x)=cos(x)
-->exec('C:\Users\Matheus\Documents\quadrat.sci', -1)
-->exec('C:\Users\Matheus\Documents\funções.sci', -1)
-->ve=0.841471;
-->n=2;
-->a=0;
-->b=1;
-->[A1,A2,A3,t1,t2,t3]=quadrat(n);
-->I=A1*f(t1,a,b)+A2*f(t2,a,b)+A3*f(t3,a,b)
 I = 0.8412698 
-->erro=ve-I
 erro = 0.0002012
c)f(x)=e^x
-->exec('C:\Users\Matheus\Documents\quadrat.sci', -1)
-->exec('C:\Users\Matheus\Documents\funções.sci', -1)
-->ve=1.718281828;
-->n=2;
-->a=0;
-->b=1;
-->[A1,A2,A3,t1,t2,t3]=quadrat(n);
-->I=A1*f(t1,a,b)+A2*f(t2,a,b)+A3*f(t3,a,b)
 I = 1.7178964 
-->erro=ve-I
 erro = 0.0003854
d)f(x)=1/(1+x)
-->exec('C:\Users\Matheus\Documents\quadrat.sci', -1)
-->exec('C:\Users\Matheus\Documents\funções.sci', -1)
-->ve=0.69314718;
-->n=2;
-->a=0;
-->b=1;
-->[A1,A2,A3,t1,t2,t3]=quadrat(n);
-->I=A1*f(t1,a,b)+A2*f(t2,a,b)+A3*f(t3,a,b)
 I = 0.6923077 
-->erro=ve-I
 erro = 0.0008395 
 
e)f(x)=x+x^3
-->exec('C:\Users\Matheus\Documents\quadrat.sci', -1)
-->exec('C:\Users\Matheus\Documents\funções.sci', -1)
-->ve=0.75;
-->n=2;	
-->a=0;
-->b=1;
-->[A1,A2,A3,t1,t2,t3]=quadrat(n);
-->I=A1*f(t1,a,b)+A2*f(t2,a,b)+A3*f(t3,a,b)
 I = 0.75 
-->erro=ve-I
 erro = 0
 
�