Sie sind auf Seite 1von 3

%Edgar Figueroa MAE305 Project3 9 May 2018

clear;clc;
%1
f=inline('x*log(x)'); truev=0.636294;

%1b
I=Simpson(f,1,2,4)
%1c
f=inline('x.*log(x)');
Ic=Gauss_Quad_4(f,1,2)
%1d
REb=(I-truev)*100/truev %Relative error in 1b
REc=(Ic-truev)*100/truev %Relative error in 1c
%Here Gauss_Quad_4 is more accurate than Simpson

function I=Gauss_Quad_4(f,a,b)
c=zeros(4,1); x=zeros(4,1);
c(1)=0.347854845; c(2)=0.652145155; c(3)=c(2); c(4)=c(1);
x(1)=-0.861136312; x(2)=-0.339981044; x(3)=-x(2);x(4)=-x(1);
x=(b-a)*(x+1.)/2+a; I=((b-a)/2)*sum(c.*f(x)); end
I=
0.6363

Ic =

0.6363

REb =

0.0025

REc =

5.2391e-05

%2 clear;clc;
disp(' x yEuler yHeun yRK4') h=.02;
x=0:h:0.2; y0=0; f=inline('y^2+exp(x)','x','y');

yEuler=EulerODE(f,x,y0);
yHeun=HeunODE(f,x,y0);
yRK4=RK4(f,x,y0);

for k=1:length(x),
x_coord=x(k);
yE=yEuler(k);
yH=yHeun(k); yR=yRK4(k);
fprintf('%6.2f %11.6f %11.6f %11.6f\n',x_coord,yE,yH,yR)
end

x yEuler yHeun yRK4


0.00 0.000000 0.000000 0.000000
0.02 0.020000 0.020206 0.020204
0.04 0.040412 0.040837 0.040833
0.06 0.061261 0.061918 0.061912
0.08 0.082573 0.083477 0.083469
0.10 0.104375 0.105542 0.105532
0.12 0.126696 0.128143 0.128132
0.14 0.149567 0.151313 0.151299
0.16 0.173020 0.175086 0.175070
0.18 0.197089 0.199496 0.199478
0.20 0.221810 0.224583 0.224563

Das könnte Ihnen auch gefallen