You are on page 1of 2

function pushbutton1_Callback(hObject, eventdata, handles)

f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
s1=0;

s2=0;
x=a;
i=1;
if(n~=2)
while(i<=(n/2-1))
x=x+h;
s1=s1+f(x);
x=x+h;
s2=s2+f(x);
i=i+1;
end
end
x=x+h;
s1=s1+f(x);
area=(h/3)*(f(a)+4*s1+2*s2+f(b));

set(handles.edit5,'string',area);
x1=a:0.05:b;
y1=f(x1);
bar(x1,y1,'r'), grid
ymin=min(y1);
ymax=max(y1)+0.1;
axis([a-0.1 b+0.1 ymin ymax])

You might also like