You are on page 1of 65

FETEL-HCMUS

Symbolic
GUI
Simulink
Bùi Trọng Tú-Huỳnh Quốc Thịnh

1
Symbolic syms x y

2
Symbolic
•Rút
  gọn biểu thức sau:

Khai báo biến x


>> syms x
>> simplify(4*cos(x)^2+ cos(2*x)+sin(x)^2)

ans =
Đơn giản hoá biểu thức
5*cos(x)^2
3
Symbolic
•Giải
  phương trình sau
với biến x và biến y

4
Symbolic
•Tính
  tích phân Q >>Q=int(x*exp(x), a, b)
với cận a=0 và Q=
b=2 exp(b)*(b-1)-exp(a)*(a-1)
>>subs(Q,(a,b),(0,2)
ans =
8.3891

5
Giải toán ký hiệu và toán số

Ưu điểm Khuyết điểm

Symbolic Cho lời giải giải tích Đôi khi không giải được
Cho cái nhìn trực quan về Có thể rất phức tạp

lời giải
Numeric Luôn cho lời giải Thường không cho thấy bản

Có thể cho lời giải chính xác chất

Dễ hiện thực bằng code Lời giải số đôi khi sai

Cần thời gian tính toán

6
GUIDE

Thiết kế với giao diện

7
Khởi động GUIDE

8 8
Guide Layout

9
Alignment tool Toolbar editor Property Inspector

Menu Editor M-file editor RUN

10
Interface Toolbars & Menus

Input Control components such as


• Push Buttons, Radio Buttons, Check Boxes
(SWITCHES)
• Pop-up Menus, List-Boxes ( SELECTIONS)
• Sliders ( CONTINIOUS CONTROL )
• Edit Text ( TEXT method of input )

Graphical Objects
• Axes Objects

Text Objects
• Static Text
11
Objects-Properties-Event

Đối tượng Push button, Sliders, Axes, Radio button…

Thuộc tính Tag, String, FontSize, Value, BackgroundColor…

Sự kiện Create, Callback,

12
Objects

13
Properties
14
Event

15
16
Hãy phân biệt cách gọi hàm dùng
handles….và hObject?
17
Handles vs hObject

Handle
hObject
s
Truy cập các đối
Áp dụng trên chính đối
tượng khác qua Tag
tượng
name

18
Get
Variable = get(Object , ‘Properties’);

a = get(hObject, ‘String’);
b = get(handles.inputB, ‘String’);

19
Set
get(Object , ‘Properties’, Value);

set(hObject, ‘String’, ‘ABC’);


set(handles.staticTextC, ‘String’, c);
% c là một biến chứa chuỗi

20
Axes
axes(handles.axesTag);
plot(x, y)
guidata(hObject, handles);

axes(handles.axes1);
x=0:10
y=x.^2
plot(x,y)
21
App Designer

Thiết kế với giao diện

22
Khởi động App Designer

Home -> New -> App

App -> Design App


Gõ lệnh appdesigner

23
Các đối tượng giao diện trong App Designer

Giao diện
Tùy chỉnh thuộc tính của đối tượng 24
Get
Variable = app.ComponentName.Properties

a = app.EditFieldA.Value;
b = app.EditFieldA.BackgroundColor;

25
Set
app.ComponentName.Properties= value

app.EditFieldTextA.Value = ‘ABC’;
app.EditFieldTextA.Value = c;
% c là một biến chứa chuỗi

26
Axes
plot(app.UIAxes, x, y);

x=0:10
y=x.^2
plot(app.AxesB, x,y)

27
Bài tập 1
Thiết kế giao diện và viết chương trình để vẽ tín
hiệu s = 2*sin(2*pi*f*n) với các thông số
được nhập vào từ giao diện:
• f: tần số tín hiệu
• fs: tần số lấy mẫu tín hiệu
• t: thời gian vẽ tín hiệu

28
Bài tập 1

29
Bài 2
Thự hiện lại bài 1 với hàm số được nhập vào từ
giao diện
Lưu ý: Hàm số là hàm một biến phụ thuộc x

30
Bài 2

31
Bài 3
• Viết giao diện
• Nhập vào 1 hàm số 1 biến
• Các nút nhấn có các chức năng: Tìm nghiệm, Phân
tích thành nhân tử
• Label để hiển thị kết quả
• Viết chương trình thực hiện chức năng trên

32
Simulink

Thiết kế và mô phỏng
với mô hình

33
Start Simulink
Gõ lệnh simulink trong Command Windows
Hoặc click vào biểu tượng Simulink

34
Library Browser
• Click vào biểu tượng Simulink -> New Model

35
Tìm kiếm

Library Browser Thư viện

Khối lệnh
36
Thư viện hay dùng

SOURCES SINKS
Nguồn tín hiệu, đầu vào Hiển thị trực quan, thiết bị đo

37
Building a Model
Tạo khối lệnh
1

Kết nối khối lệnh


2

Tùy chỉnh tham số


3

Thực hiện mô phỏng


4

38
Tạo khối lệnh
Kéo thả khối lệnh từ thư viện để tạo mô hình

39
Lưu ý

• Chúng ta có thể double-


click lên vùng vẽ để tìm
kiếm khối lệnh cần dùng

40
Kết nối khối lệnh

Kéo chuột từ các đầu vào ra để kết nối

41
Tùy chỉnh tham số
Double-click lên khối lệnh
để tùy chỉnh tham số

42
Cấu hình mô phỏng
Vào biểu tượng setting, sau đó
cấu hình thời gian mô phỏng

43
Thực hiện mô phỏng
Nhấn vào biểu tượng Run để mô phỏng

44
Quan sát kết quả

Double-click vào khối


hiển thị để xem kết
quả

45
Phiên bản Matlab cũ

46
Start a Simulink Session
Click on the SIMULINK icon on toolbar

Type simulink
on Matlab command window

47
Simulink Library Browser
CREAT NEW MODEL icon SEARCH window

BLOCK set
for model construction

LIBRARY
48
Create a New Model
CREAT NEW MODEL icon

Workspace where you


construct your model

49
Building a Model
• Step 1: Creating Blocks
Save this model

This is the
Sine Wave block is
from the Sources library

Click-Drag-Drop the Sine Wave block to Workspace Window


Sources library
50
Building a Model
• Step 1: Creating Blocks

The Gain
block is
from the
Math library

These are
The Mux block is from from the Sinks
the Signals &Systems library library

51
Building a Model
• Step 2: Making connections
To make connection: left-click while holding down control key (on keyboard)
and drag from source port to a destination port

A connected Model

52
Building a Model
 Step 3: Set Parameters
Double click the Gain block to set the parameter for the Gain block

Name the output


parameter as “out1”

Gain value = 5

53
Building a Model
 Step 4: Running Simulation
Click here to run the simulation

click “simulation parameters” to set


up the desired parameters
You can change the “stop time” and
then click the “OK button”
54
Building a Model
 View output via Scope block

Output of the scope

To fit graph to frame

Yellow: Input sine wave


Purple: Output (sine wave with gain of 5

Double click on Scope block to display output of the scope


Note: Scope block is similar to oscilloscope!
55
Building a Model
 View output (workspace)

You can plot the output using the plot function

Three outputs show here


56
57
Example : Transfer Function (1)

1
x   2 x  2 x  f  t  
2
The transfer function of the equation
(assume all initial conditions =0)

X ( s) 1
 2
F ( s) 2s  2s  2
58
Example: Transfer Function (2)

STEP 1: Creating Blocks


Select BLOCK set Location in Simulink Library
Step Sources

Transfer Function Continuous

Scope & To Workspace Sinks

59
Example 2: Transfer Function (3)

STEP 2: Making connections

60
Example 2: Transfer Function (4)

STEP 3: Set Parameters


Set Step time =0
x

61
Example 2: Transfer Function (5)

STEP 4: Running Simulation


1 Open “simulation parameters” window
2
RUN
Set “Stop time” = 30
Simulation

62
Example 2: Transfer Function (6)

Output from Scope block Plot system response


63
CÂU HỎI

64
FETEL-HCMUS

Thank you!

65
HQT

You might also like