10:26 AM

MID-POINT RULE

A friend from yahoo answers asked me to write this program.So here it is:


function mid_point_rule

F=input('enter the function: ','s');
F=inline(F);

a=input('Enter the lower limit: ');
b=input('Enter the upper limit: ');
n=input('Enter the number of rectangles to be used(even number): ');

del_x=(b-a)/n;

sum=0;
for i=1:n
    x1=a+i*del_x;
    x0=a+(i-1)*del_x;
    x_mean=(x1+x0)/2;
  
    sum=sum+F(x_mean);
end
integ=del_x*sum;
fprintf('\nHence the integration is %d\n',integ);


Main formula:


Midpoint Rule:
where,






PLEASE LEAVE A COMMENT :)

0 comments:

Post a Comment