as the title said, this is what i have:
clear allclca=0; b=8;n=2;run=input('Input your number of iteration:');i=(1:run);for ii=1:length(i) n=2*n; h=(b-a)./n; fprintf('n= %4.0f and h= %5.3f\n',n, h) integral = 0; si=(1:h:b); for i = 1:length(si)-1 x_left=a+(i-1)*h; x_right=a+i*h; x_half=(x_left+x_right)/2.0; f_half=0.0041.*(x_half.^6)-0.1383.*(x_half.^5)+1.6963.*(x_half.^4)-8.915.*(x_half.^3)+13.961.*(x_half.^2)+40.96.*(x_half); integral=integral+f_half*h; end fprintf('The distance travel is %5.5f miles\n', integral)
Best Answer