%Lab 2
%Written by Jeannette Spuhler, 2011-09-07
%Moddified 2011-11-03


%trapezoidal rule
%NUM 6.2a
clear all; clc; 
n=10; %så många delintervaller
h=3/n; 
xapp=0:h:3; 
fapp=f62a(xapp);

% Trapets regel!!!
T = h*(sum(fapp)-0.5*(fapp(1)+fapp(n+1)));
disp('The approximation with trapezoidal rule for the integral is ');
disp(T);

%for plotting the approximation
n1=100;
h=3/n1; 
x=0:h:3; 
f=f62a(x); 
plot(x,f, 'g'); hold on;
plot(xapp,fapp); hold on;
for i=1:n+1
 line([xapp(i) xapp(i)] ,[0 fapp(i)]); hold on;
end
title('Lab2 -Trapezoidal rule'); 
ylabel('exp(x)./(1+2*x.^3)');
xlabel('x');


hold off;

