Toán Nâng Cao Chuyên Ngành Cơ Điện Tử

You might also like

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

TOÁN NÂNG CAO

CHUYÊN NGÀNH
CƠ ĐIỆN TỬ
Nội suy

Mechatronic Division, Faculty of Mechanical Engineer


Vo Nhu Thanh, Ph.D, Senior Lecturer
2
3
4
5
6
7
8
9
10
Bài về nhà
(chú ý các
điều kiện)

11
12
13
14
15
function divdif_y = divdif(x_nodes,y_values)
% Day la ham
% divdif_y = divdif(x_nodes,y_values)
% No se tinh toan cac ty sai phan cua ham. Gia tri cho truoc trong vector
%y_values, la gia tri cua ham f(x) tai nut da cho x_nodes. Voi,
% divdif_y(i) = f[x_1,...,x_i], i=1,...,m
% m la do dai cua x_nodes. Nhap vao gia tri cua x_nodes va y_values phu %hop voi chuong
trinh.
divdif_y = y_values;
m = length(x_nodes);
for i=2:m
for j=m:-1:i
divdif_y(j) = (divdif_y(j)-divdif_y(j-1)) ...
/(x_nodes(j)-x_nodes(j-i+1));
end
end
% Ch?y ch??ng trình v?i: x_nodes=[0.0 0.2 0.4 0.6 0.8 1.0 1.2];
% y_values=[1.0 0.980067 0.921061 0.825336 0.696707 0.540302 0.362358];

16
17
18
19
20
21
22
23
24
function testpolyfit
% x=[1 1 2 2 2 3 3 4 5 6];y=[1 2 2 3 4 4 5 5 6 7];n=1; % Vi du 4.4.1.
x=[1 1 2 3 3 4 5];y=[4.12 4.18 6.23 8.34 8.38 12.13 18.32]; n=2; % Vi du 4.4.2
%x=[1 1 2 3 4 4 5];y=[3 4 6 9 12 13 20];n=3;% Da thuc bac ba.
f=polyfit(x,y,n)
x2 = 1:.1:5;
y2 = polyval(f,x2);
plot(x,y,'ro',x2,y2,'LineWidth',2)
title('Hinh 4.3. Do thi cua da thuc f (mau xanh) va cac diem du kien (mau do)')
grid on
% input x=[1 1 2 3 3 4 5];y=[4.12 4.18 6.23 8.34 8.38 12.13 18.32]; n=2;

25
26
Faculty of Mechanical Engineer
Vo Nhu Thanh, Ph.D, Senior lecturer

END CHAPTER

27 27

You might also like