Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

function xapxitichphan

syms Iht Iss I t x y f a b n h q d yM2 M2 f2 f3 x3 sht


f = input('Nhap ham f bien x: ');
a = input('Nhap chi so dau a: ');
b = input('Nhap chi so cuoi b: ');
d = input('Nhap so luong khoang: ');
n = d+1;
h = abs(a-b)/d
f2 = simplify(abs(diff(f,2)))
f3 = diff(f2);
x3 = solve(f3,0);
yM2(1) = subs(f2,a);
yM2(length(x3)+2) = subs(f2,b);
for i = 2:length(x3)+1
yM2(i) = subs(f2,x3(i-1));
end;
M2 = max(yM2);
fprintf(' Gia tri M2 la: %0.8f \n',M2);
% hinh thang
for i = 1:n
x(i) = a+(i-1)*h;
y(i) = subs(f,x(i));
end;
Iht = h*(sum(y)-(y(1)+y(d))/2);
fprintf(' Tich phan tinh theo cong thuc hinh thang la: %0.8f \n',Iht);
sht = ((b-a)*(h^2)*M2)/12;
fprintf(' Sai so tinh theo cong thuc hinh thang la: %0.8f \n',sht);
% simpson

You might also like