echo on % % Enter the data, % e.g. paste from EXCEL % A=[0,5;5,13;10,16;15,17;20,... 18;25,18;30,17;35,16;... 40,13;45,10;50,2;] pause % % Pick the x and the y column % y=A(:,1) x=A(:,2) pause % % plot the data, check for errors % plot(x,y,'ro') pause % % get help for polyfit % pause help polyfit % % pause % % Fit our data x=p(y) % pause p8=polyfit(y,x,8) pause % % need to evaluate the polynomial % at the given y-data points % pause help polyval pause % % check that things are as desired % use only few data points now! % pause yy=[0:10:50]' pause xx=polyval(p8,yy) pause plot(xx,yy,'b-',x,y,'r*') % % Now work with real data, e.g. % 50 points instead of 5 points % yy=[0:1:50]'; xx=polyval(p8,yy); plot(xx,yy,'b-',x,y,'ro') pause % % Still need to make the grafix % nicer. Some help pages.... % pause help axes pause help axis pause axis equal pause axis([0,50,0,50]) pause % % Now back to Riemann sums, but % working with interpolated data % pause % % First the volumes. You may want % to dry-run this with a smaller % data set first..... % pause vols=pi*xx.^2*1; vols(1:5) % % Volumes of the slices % Showing oinly the first 5 % The units are (mm)^3 % pause masses=vols*0.9/1000; masses(1:5) % % Masses of the slices % Showing oinly the first 5 % Note the unit conversion % Now mass in grams % pause inertias=masses.*(xx.^2)/2; inertias(1:5) % % Moments of inertia of slices % Showing only the first 5 % Units: grams*(mm)^2 % pause totiner=sum(inertias)/100 % % Total moment of inertia % units converted to g*(cm)^2