No BSD License  

Highlights from
Alternative Mathematics using MATLAB 7

image thumbnail

Alternative Mathematics using MATLAB 7

by

 

13 Mar 2003 (Updated )

Self-instructive text on undergraduate algebra, statistics, differential and integral calculus.

ex153.m
% ex153.m:  Simpson Integration of cos(x)				         
clear all,  format long
xn=input('xn= (e.g. 1) ');		% Input right end coordinate
x1=0;  n=500;						% Even number of sub-intervals
h=(xn-x1)/n;  						% Length of sub-intervals
X=x1: h: xn;						% Interval coordinates (n+1)
sumi=0;   							% Reset sumi		
for i=3:2:n+1 						% For i=3,5,7,n+1
   sumi=sumi+ cos(X(i-2))+ 4*cos(X(i-1))+ cos(X(i));		% Add area
end
integral=sumi*h/3;
int_ex=sin(xn)-sin(x1);			% Exact integral
integrals=[integral int_ex]		% Display comparison
format short e,  error=integral-int_ex

Contact us