⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fourpole1.m

📁 控制系统仿真中的根轨迹MATLAB仿真源码
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = fourpole1(varargin)
% FOURPOLE1 M-file for fourpole1.fig
%      FOURPOLE1, by itself, creates a new FOURPOLE1 or raises the existing
%      singleton*.
%
%      H = FOURPOLE1 returns the handle to a new FOURPOLE1 or the handle to
%      the existing singleton*.
%
%      FOURPOLE1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FOURPOLE1.M with the given input arguments.
%
%      FOURPOLE1('Property','Value',...) creates a new FOURPOLE1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before fourpole1_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to fourpole1_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 fourpole1

% Last Modified by GUIDE v2.5 26-May-2005 15:10:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @fourpole1_OpeningFcn, ...
                   'gui_OutputFcn',  @fourpole1_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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 fourpole1 is made visible.
function fourpole1_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 fourpole1 (see VARARGIN)

% Choose default command line output for fourpole1
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes fourpole1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);

%在小坐标图上标明a,b,c代表的线段
Axes=axes('Position',[0.684,0.73,0.207,0.24],'visible','off');
z=[]
p=[0 -10 -5+6i -5-6i]
sys=zpk(z,p,1)
rlocus(sys)
hold on 

%设置当前窗口名
str='四个极点分布对根轨迹的影响';
set(gcf,'name',str,'numbertitle','off')
% --- Outputs from this function are returned to the command line.
function varargout = fourpole1_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 during object creation, after setting all properties.function edit_a_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit_a (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    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_a_Callback(hObject, eventdata, handles)% hObject    handle to edit_a (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 edit_a as text%        str2double(get(hObject,'String')) returns contents of edit_a as a double% --- Executes during object creation, after setting all properties.function slider_a_CreateFcn(hObject, eventdata, handles)% hObject    handle to slider_a (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray background, change%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.usewhitebg = 1;if usewhitebg    set(hObject,'BackgroundColor',[.9 .9 .9]);else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end% --- Executes on slider movement.function slider_a_Callback(hObject, eventdata, handles)% hObject    handle to slider_a (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,'Value') returns position of slider%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

%接受编辑框中的a,b,c的值并绘制根轨迹图set(handles.edit_a,'string',num2str(get(handles.slider_a,'value')));
val1=str2num(get(handles.edit_a,'string'))
a=str2num(get(handles.edit_a,'string'))
if isnumeric(val1)&length(val1)==1&...
        val1>=get(handles.slider_a,'Min')&...
        val1<=get(handles.slider_a,'Max')
    set(handles.slider_a,'Value',val1);
else  handles.numberofErrors=handles.numberofErrors+1;
    set(handles.edit_a,'String',...
        [handles.errorString,num2str(handle.numberofErrors)]);
    guidata(gcbo,handle);
end
set(handles.edit_b,'string',num2str(get(handles.slider_b,'value')));
val2=str2num(get(handles.edit_b,'string'))
b=str2num(get(handles.edit_b,'string'))
if isnumeric(val2)&length(val2)==1&...
        val2>=get(handles.slider_b,'Min')&...
        val2<=get(handles.slider_b,'Max')
    set(handles.slider_b,'Value',val2);
else  handles.numberofErrors=handles.numberofErrors+1;
    set(handles.edit_b,'String',...
        [handles.errorString,num2str(handle.numberofErrors)]);
    guidata(gcbo,handle);
end
set(handles.edit_c,'string',num2str(get(handles.slider_c,'value')));
val3=str2num(get(handles.edit_c,'string'))
c=str2num(get(handles.edit_c,'string'))
if isnumeric(val3)&length(val3)==1&...
        val3>=get(handles.slider_c,'Min')&...
        val3<=get(handles.slider_c,'Max')
    set(handles.slider_c,'Value',val3);
else  handles.numberofErrors=handles.numberofErrors+1;
    set(handles.edit_c,'String',...
        [handles.errorString,num2str(handle.numberofErrors)]);
    guidata(gcbo,handle);
end
p1=0
p2=-(a+b)
p3=-a+(1/2)*c*i
p4=-a-(1/2)*c*i
z=[]
p=[p1 p2 p3 p4]
sys=zpk(z,p,1)
subplot('Position',[0.1,0.35,0.422,0.5])
rlocus(sys)

%得出当系统稳定时K的值
num=poly(z)
den=poly(p)
syms('x','w','k','real')
n=poly2sym(k*num,x)
d=poly2sym(den,x)
f=n+d
g=w*i
h=compose(f,g)
r=real(h)
l=simplify(imag(h))
[k,w]=solve(r,l)
k1=sym2poly(k)
if min(k1)<0
    set(handles.edit_stastic,'string',0)
else
    set(handles.edit_stastic,'string',min(k1))
end
if max(k1)<0
    set(handles.edit_stastic1,'string',inf)
else
   set(handles.edit_stastic1,'string',max(k1))
end
% --- Executes during object creation, after setting all properties.function edit_b_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit_b (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    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_b_Callback(hObject, eventdata, handles)% hObject    handle to edit_b (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 edit_b as text%        str2double(get(hObject,'String')) returns contents of edit_b as a double% --- Executes during object creation, after setting all properties.function slider_b_CreateFcn(hObject, eventdata, handles)% hObject    handle to slider_b (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray background, change%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.usewhitebg = 1;if usewhitebg    set(hObject,'BackgroundColor',[.9 .9 .9]);else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end% --- Executes on slider movement.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -