1. Trang chủ
  2. » Luận Văn - Báo Cáo

Bai 4 thuc hanh thiet ke mo hinh hoa mo phong xe bus phuc vu

31 537 2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 31
Dung lượng 1 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

'THUC SU MUON THOAT?','Yes','No','No'; function edit6_CallbackhObject, eventdata, handles % hObject handle to edit6 see GCBO % eventdata reserved - to be defined in a future version of M

Trang 1

Bài 4 XÂY DỰNG MÔ HÌNH HÓA MÔ PHỎNG XE BUS PHỤC VỤ NHÂN DÂN

TRÊN CÔNG CỤ GUIDE CỦA PHẦN MỀM MATLAB

I Mục đích

- Giúp sinh viên hiểu phương pháp xây dựng mô hình hóa mô phỏng một hệ thống vật lý

- Thu thập và phân tích các bảng dữ liệu của hệ thống

- Đánh giá được kết quả mô phỏng, so sánh độ tương đồng giữa kết quả mô phỏng của mô hình với các tính chất của đối tượng thực

- Đưa ra kết luận và các phương án điều chỉnh cho đối tượng thực dựa trên kết quả mô phỏng sau khi phân tích chúng

II Yêu cầu thực hành

- Máy vi tính cài đặt sẵn phần mềm Matlab với đầy đủ các ứng dụng của Math Work cung cấp

- Yêu cầu sinh viên được trang bị phần lý thuyết môn Tin học chuyên ngành, hết chương 4 Mô phỏng hệ ngẫu nhiên môn Mô hình hóa

- Tuân thủ mọi nội quy, quy định khi thực hành tại phòng thí nghiệm

III Nội dung thực hành

3.1 Bài toán yêu cầu

Mô phỏng trạm xe bus sinh viên Sinh viên đi từ ký túc xá đến trường bằng xe bus, mỗi xe chứa được 60 sinh viên Thời gian đi đến trường bắt đầu từ 6h đến 7h Sinh viên đi đến trạm xe bus được mô tả bằng một dòng tối giản với cường độ λ = 0.8 SV/s Cứ sau Txe = 15 phút có một chuyến xe bus đi đến trường Nếu số sinh viên chờ xe <60 SV xe chạy đúng giờ Nếu số SV chờ xe >60SV thì số SV thừa sẽ phải chờ đến chuyến xe sau

Xây dựng mô hình mô phỏng hệ thống trên Kiểm tra xem sau 7h30 thì còn bao nhiêu SV bị kẹt xe tại bến xe bus

Để đảm bảo tất cả sinh viên đi học đúng giờ thì Txe = ??

3.2 Các bước tiến hành

Trang 2

Bước 1 Thuật toán mô phỏng:

B1 Xây dựng mô hình dòng sinh viên đi đến trạm xe bus Khoảng thời gian giữa các sinh viên đi đến trạm xe bus

là ti = (-1/λ)ln(Ui) với Ui ~ U(0,1)

B2 Thời gian mô phỏng là từ 6h đến 7h tức t = 0 đên t = 3600s

t = t + ti khi t = 3600s thì dừng mô phỏng

B3 Nếu t <3600s thì số sinh viên ở trạm c = c +1 khi có 1 sinh viên đến trạm

B4 Khi t = Tx, t = 2Tx, t = 3Tx… (tức t/Tx không có dư) Kiểm tra số sinh viên ở trạm là c

- Nếu c<60 (Tức 1 xe 60 chỗ có thể cho hết số sinh viên trong trạm lên) khi đó sau khi xe đi thì không có sinh viên còn phải chờ ở chạm tức c = 0

- Nếu c>60 khi đó số sinh viên còn chờ ở bến xe bus là c = c - 60

B5 Khi t = 3600s thì đếm c = ??? Khi đó ta thay đổi Tx để c = 0

Trang 3

Bước 2 Xây dựng giao diện mô phỏng hệ thống điều khiển tự động

(1) Khởi tạo guide trong phần mềm Matlab

Trang 4

(2) Thiết lập bảng điều khiển trên giao diện

- Chọn công cụ Panel

Trang 5

- Thay đổi tên cho Panel bằng cách kích đúp vào Panel và thay tên trong phần Title của nó từ tên

- Panel sang tên “Bang dieu

khien”

-

Trang 6

- Chọn công cụ Push Button để khai báo nút khảo sát hệ thống

Trang 7

Đổi tên PushButton trong String ở Inspector của nút sang tên mới là khảo sát hệ thống

Trang 8

+ Kết quả thu được

Trang 9

+ Tương tự như vậy ta lấy nút có tên gọi là “Thoát khỏi hệ thống”

Trang 10

- Chọn công cụ Panel để khai báo bảng nhập giá trị

Trang 11

- Chọn công cụ Static Text để định nghĩa các ô nhập giá trị từ bàn phím

Trang 12

+ Kích đúp vào Static Text để thay đổi tên Static Text trong String sang tên “Nhap so ghe ngoi cua xe N =”

+Tương tự như vậy ta khai báo nhập giá trị cho Txe, lamda, T

- Chọn công cụ Edit Text để khai báo ô nhập và xuất giá trị trên màn hình

+ Kích đúp vào Edit1 để khai báo giá trị mặc định cho hệ số N = 60 trong phần String từ chuỗi ký tự “ Edit Text” sang

số 60 Làm tương tự chọn Edit2, Edit3,Edit4 cho các biến TxTe, lamda, với mặc định lamda = 0.8; và T = 3600 Txe =

900

Trang 14

+ Tương tự ta lập bảng xuất giá trị tính toán ra:

> Số sinh viên đợi ở bến trong thời gian khảo sát xuất ra Edit5 > Số sinh viên đến trường đúng giờ xuất ra Edit6 >

> Số sinh viên đến trường muộn giờ xuất ra Edit7

Trang 16

Bước 3 Viết Code cho các nút điều khiển

(1) Nút thoát khỏi hệ thống

Nhấn chuột phải vào Nút “ Thoat khoi he thong” chọn View callBacks/Callback

Trang 17

+ Ta lập trình như sau:

hoi=questdlg('Ban muon thoat khoi chuong trinh?',

'THUC SU MUON THOAT?','Yes','No','No');

Trang 19

(2) Nút “Khao sat he thong”

Nhấn chuột phải vào Nút “Khao sat he thong” chọn View callBacks/Callback

Trang 20

+ Ta lập trình:

function varargout = Bai4(varargin)

% BAI4 MATLAB code for Bai4.fig

% BAI4, by itself, creates a new BAI4 or raises the existing

% singleton*

%

% H = BAI4 returns the handle to a new BAI4 or the handle to

% the existing singleton*

%

% BAI4('CALLBACK',hObject,eventData,handles, ) calls the local

% function named CALLBACK in BAI4.M with the given input arguments

%

% BAI4('Property','Value', ) creates a new BAI4 or raises the

% existing singleton* Starting from the left, property value pairs are

% applied to the GUI before Bai4_OpeningFcn gets called An

% unrecognized property name or invalid value makes property application

% stop All inputs are passed to Bai4_OpeningFcn via varargin

%

% *See GUI Options on GUIDE's Tools menu Choose "GUI allows only one

% instance to run (singleton)"

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Bai4

% Last Modified by GUIDE v2.5 06-Mar-2013 19:38:03

% Begin initialization code - DO NOT EDIT

Trang 21

gui_mainfcn(gui_State, varargin{:});

end

% End initialization code - DO NOT EDIT

% - Executes just before Bai4 is made visible

function Bai4_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% varargin command line arguments to Bai4 (see VARARGIN)

% Choose default command line output for Bai4

% - Outputs from this function are returned to the command line

function varargout = Bai4_OutputFcn(hObject, eventdata, handles)

% varargout cell array for returning output args (see VARARGOUT);

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

varargout{1} = handles.output;

% - Executes on button press in pushbutton1

function pushbutton1_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Ch??ng trình ví du 3.1 v? v? ?? th? c?a h? th?ng ?i?u khi?n t? ??ng

disp('MO PHONG HE THONG XE BUS PHUC VU - THM')

clc;

% Khai bao bien

syms N lamda Txe Ts Ndg Nm

N = get(handles.edit1,'String');% Nhan chuoi ky tu trong edit1 gán cho N

Trang 22

N = str2num(N); %Chuyen gia tri chuoi ký tu sang dang so

Txe = get(handles.edit2,'String');% Nh?n chu?i ký t? ? edit3 gán cho t1

Txe = str2num(Txe); %Chuy?n ??i t? chu?i ký t? sang d?ng s?

lamda = get(handles.edit3,'String');% Nh?n chu?i ký t? ? edit2 gán cho k2

lamda = str2num(lamda); %Chuy?n ??i t? chu?i ký t? sang d?ng s?

T = get(handles.edit4,'String');% Nh?n chu?i ký t? ? edit3 gán cho t1

T = str2num(T); %Chuy?n ??i t? chu?i ký t? sang d?ng s?

Trang 23

% - Executes on button press in pushbutton2.

function pushbutton2_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

hoi=questdlg('Ban muon thoat khoi chuong trinh?',

'THUC SU MUON THOAT?','Yes','No','No');

function edit6_Callback(hObject, eventdata, handles)

% hObject handle to edit6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text

% str2double(get(hObject,'String')) returns contents of edit6 as a double

% - Executes during object creation, after setting all properties

function edit6_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows

% See ISPC and COMPUTER

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

function edit7_Callback(hObject, eventdata, handles)

Trang 24

% hObject handle to edit6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text

% str2double(get(hObject,'String')) returns contents of edit6 as a double

% - Executes during object creation, after setting all properties

function edit7_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows

% See ISPC and COMPUTER

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

function edit8_Callback(hObject, eventdata, handles)

% hObject handle to edit8 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text

% str2double(get(hObject,'String')) returns contents of edit8 as a double

% - Executes during object creation, after setting all properties

function edit8_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit8 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows

% See ISPC and COMPUTER

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

Trang 25

function edit1_Callback(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text

% str2double(get(hObject,'String')) returns contents of edit1 as a double

% - Executes during object creation, after setting all properties

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows

% See ISPC and COMPUTER

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

function edit2_Callback(hObject, eventdata, handles)

% hObject handle to edit2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text

% str2double(get(hObject,'String')) returns contents of edit2 as a double

% - Executes during object creation, after setting all properties

function edit2_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows

% See ISPC and COMPUTER

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

Trang 26

function edit3_Callback(hObject, eventdata, handles)

% hObject handle to edit3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text

% str2double(get(hObject,'String')) returns contents of edit3 as a double

% - Executes during object creation, after setting all properties

function edit3_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows

% See ISPC and COMPUTER

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

function edit9_Callback(hObject, eventdata, handles)

% hObject handle to edit6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text

% str2double(get(hObject,'String')) returns contents of edit6 as a double

% - Executes during object creation, after setting all properties

function edit9_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows

% See ISPC and COMPUTER

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

Trang 27

function edit5_Callback(hObject, eventdata, handles)

% hObject handle to edit5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text

% str2double(get(hObject,'String')) returns contents of edit5 as a double

% - Executes during object creation, after setting all properties

function edit5_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows

% See ISPC and COMPUTER

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

function edit11_Callback(hObject, eventdata, handles)

% hObject handle to edit5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text

% str2double(get(hObject,'String')) returns contents of edit5 as a double

% - Executes during object creation, after setting all properties

function edit11_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows

% See ISPC and COMPUTER

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

Ngày đăng: 10/06/2016, 19:08

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w