Tải bản đầy đủ (.pdf) (29 trang)

Bai 3 thuc hanh thiet ke mo hinh hoa mo phong do tin cay cua thiet bi dien tu

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.02 MB, 29 trang )

Bài 3. XÂY DỰNG MÔ HÌNH HÓA MÔ PHỎNG ĐỘ TIN CẬY CỦA THIẾT BỊ ĐIỆN TỬ
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
Dùng phương pháp mô phỏng để tính toán độ tin cậy của thiết bị, biết cường độ hỏng hóc λ = 2 10-3 (l/h). Hãy vẽ đường
cong biểu diễn độ tin cậy P(t) lý thuyết và P(t) mô phỏng khi số lần thực nghiệm là S = 300, S = 1000, S = 3000;
3.2. Các bước tiến hành
.Do cường độ hỏng hóc của thiết bị λ(lan/gio)=const nên dòng hỏng hóc là dòng tối giản. Như vậy khoảng cách giữa các
lần hỏng hóc ti tuân theo luật phân bố mũ.
Gọi T là thời gian khảo sát. Thiết bị được coi là làm việc tin cậy khi khoảng cách giữa các lần hỏng hóc lớn hơn
thời gian khảo sát ti>T (Trong khoảng thời gian khảo sát thì thiết bị không bị hỏng). Như vậy độ tin cậy là P(ti>T).
Bước 1. Thuật toán mô phỏng:


(1). Lấy một số ngẫu nhiên Ui ~ U(0,1). Vậy ti = - ln(Ui/ λ).
(2). So sánh ti với T:
Nếu ti > T thiết bị làm việc tin cậy.
Nếu ti < T thiết bị làm việc không tin cậy.
(3). Thực hiện N thử nghiệm
Độ tin cậy của thiết bị được đánh giá như sau:


P(ti>T) = Số thiết bị làm việc tin cậy/Số thiết bị thử nghiệm
(4). Độ tin cậy lý thuyết P*(t) = expo(-λT).
(5). So sánh giữa P(t) và P*(t)


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


(2) Thiết lập bảng điều khiển trên giao diện
- Chọn công cụ Panel


- 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”


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

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


+ Kết quả thu được



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


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


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


+ Kích đúp vào Static Text để thay đổi tên Static Text trong String sang tên “Nhap so thiet bi thu nghiem N =”


+Tương tự như vậy ta khai báo nhập giá trị cho 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 = 3000 trong phần String từ chuỗi ký tự “ Edit Text” sang
số 3000. Làm tương tự chọn Edit2, Edit3 cho các biến lamda, T với mặc định lamda = 0.002; và T = 2.

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


> Độ tin cậy lý thuyết xuất ra Edit4 > Số thiết bị làm việc tin cậy xuất ra Edit6 > Sai lệch ra Edit8
> Độ tin cậy mô phỏng xuất ra Edit5
> Số thiết bị làm việc không tin cậy xuất ra Edit7

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

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


hoi=questdlg('Ban muon thoat khoi chuong trinh?',...
'THUC SU MUON THOAT?','Yes','No','No');
if strcmp(hoi,'Yes')
close
if strcmp(hoi,'No')
return;
end
end



(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


+ Ta lập trình:
function varargout = Bai3(varargin)
% BAI3 MATLAB code for Bai3.fig
%
BAI3, by itself, creates a new BAI3 or raises the existing
%
singleton*.
%
%

H = BAI3 returns the handle to a new BAI3 or the handle to
%
the existing singleton*.
%
%
BAI3('CALLBACK',hObject,eventData,handles,...) calls the local
%
function named CALLBACK in BAI3.M with the given input arguments.
%
%
BAI3('Property','Value',...) creates a new BAI3 or raises the
%
existing singleton*. Starting from the left, property value pairs are
%
applied to the GUI before Bai3_OpeningFcn gets called. An
%
unrecognized property name or invalid value makes property application
%
stop. All inputs are passed to Bai3_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 Bai3
% Last Modified by GUIDE v2.5 06-Mar-2013 15:29:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;

gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Bai3_OpeningFcn, ...
'gui_OutputFcn', @Bai3_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback',
[]);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Bai3 is made visible.
function Bai3_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 Bai3 (see VARARGIN)
% Choose default command line output for Bai3

handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Bai3 wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Bai3_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 DANH GIA DO TIN CAY CUA THIET BI DIEN TU - THM')
clc;
% Khai bao bien
syms N lamda T
N = get(handles.edit1,'String');% Nhan chuoi ky tu trong edit1 gán cho N

N = str2num(N);
%Chuyen gia tri chuoi ký tu sang dang so
lamda = get(handles.edit2,'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.edit3,'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?
sothietbilamviectincay=0;
for i = 1:N
Ui = rand(1);
ti = -(log(Ui)/lamda);
if ti>=T
sothietbilamviectincay = sothietbilamviectincay+1;
end
end
% Do tin cay mo phong la
Pt = (sothietbilamviectincay/N);
set(handles.edit5,'String',Pt);
% Do tin cay ly thuyet la
Plt = exp(-lamda*T);
set(handles.edit4,'String',Plt);
%So thiet bi lam viec tin cay.
set(handles.edit6,'String',sothietbilamviectincay);
%So thiet bi lam viec khong tin cay.
sothietbilamvieckhongtincay = N-sothietbilamviectincay;
set(handles.edit7,'String',sothietbilamvieckhongtincay);
subplot(2,2,2);

pie([sothietbilamviectincay sothietbilamvieckhongtincay ],{'So thiet bi lam viec tin cay','So thiet bi lam viec
khong tin cay'})
% Sai lech giua ly thuyet va mo phong
sailech= (abs(Pt-Plt)/Plt)*100
set(handles.edit8,'String',sailech);

% --- 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');
if strcmp(hoi,'Yes')
close
if strcmp(hoi,'No')


return;
end
end

function edit6_Callback(hObject, eventdata, handles)
% hObject
handle to edit4 (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 edit4 as text
%
str2double(get(hObject,'String')) returns contents of edit4 as a double

% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject
handle to edit4 (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)
% hObject
handle to edit7 (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 edit7 as text
%
str2double(get(hObject,'String')) returns contents of edit7 as a double

% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)

% hObject
handle to edit7 (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

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

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


×