📄 time.asv
字号:
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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction 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 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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction 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 edit9_CreateFcn(hObject, eventdata, handles)% hObject handle to edit9 (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 edit9_Callback(hObject, eventdata, handles)% hObject handle to edit9 (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 edit9 as text% str2double(get(hObject,'String')) returns contents of edit9 as a double% --- Executes during object creation, after setting all properties.function edit10_CreateFcn(hObject, eventdata, handles)% hObject handle to edit10 (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 edit10_Callback(hObject, eventdata, handles)% hObject handle to edit10 (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 edit10 as text% str2double(get(hObject,'String')) returns contents of edit10 as a doublefunction [result,k]=routh(den)
if den(1)<0 %如果特征根方程首项系数为负,则异号
den=-den;
end
result=1; %假设初始系统稳定
k=0; %存放劳斯行列式变号次数,即不稳定根个数
n=length(den); %得到特征根系数个数
if(n==1)
return;
end
row1=den(1:2:n); %得到劳斯行列式第一行
row2=den(2:2:n); %得到劳斯行列式第二行
l1=length(row1);
l2=length(row2);
if(n==2) %一阶系统
if(row1*row2<0) %存在一个正根时不稳定
result=-1;
k=1;
return;
else
return;
end
end
if(row2(1)<0) %如果第二行首项为负时,不稳定
result=-1;
k=k+1;
elseif(abs(row2(1))<eps) %如果第二行首项为零
if(length(find(row2~=0)>0)) %如果第二行存在非零项,把首项设为极小值
row2(1)=eps;
else
for i=1:l1 %如果为全零行,对第一行求导后替换
row2(i)=row1(i)*(n-2*i+1);
end
end
end
l1=length(row1);
l2=length(row2);
row=[row1;row2,zeros(1,l1-l2)];
row=[row;zeros(n-2,l1)]; %在只有前两行的情况下先补全矩阵
for i=3:n
for j=1:l1-1
aaa=[row(i-2,1),row(i-2,j+1);row(i-1,1),row(i-1,j+1)]; %从第三行开始计算行列式
row(i,j)=-det(aaa)/row(i-1,1) ;
end
if(row(i,1)<0) %第i行首项为负时系统不稳定
result=-1;
elseif(abs(row(i,1))<eps) %如果第i行首项为零
if(length(find(row(i,:)~=0)>0)) %如果第i行存在非零项,把首项设为极小值
row(i,1)=eps;
else
for(k=1:l1)
row(i,k)=row(i-1,k)*(n-i+3-2*k);%如果为全零行,对第一行求导后替换
end
end
end
if(row(i,1)*row(i-1,1)<0) %统计首项变号次数,即为不稳定特征根的个数
k=k+1;
end
end
%row
function show(sys,tffeedback,handles)
axes(handles.axes1)
cla %清除图象
t=0:0.01:15;
y=step(sys,t);
plot(t,y,'b',t,ones(length(t),1),'k'); %画出单位阶跃响应曲线
xlabel('Time(sec)');
ylabel('Response');
title('阶跃响应曲线');
s=length(t);
stable_val=y(s);
[ymax,tp]=max(y);
peaktime=t(tp);
max_overshoot=(ymax-y(s))/y(s); %求超调
stac=lsim(tffeedback,y,t)-1;
ss=length(stac);
ess=stac(ss); %求稳态误差
while y(s)<1.02*stable_val&y(s)>0.98*stable_val
s=s-1;
end
settle_time=t(s+1); %求调节时间
set(handles.edit7,'string',settle_time)
set(handles.edit8,'string',max_overshoot)
set(handles.edit9,'string',ess)% --- 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)set(handles.edit1, 'String',1); %恢复到初始状态
set(handles.edit2, 'String',1);
set(handles.edit3, 'String',1);
set(handles.edit4, 'String',1);
set(handles.edit10, 'String',[],'visible','off');
set(handles.text6,'visible','off')
set(handles.edit7, 'String',0,'visible','off');
set(handles.edit8, 'String',0,'visible','off');
set(handles.edit9, 'String',0,'visible','off');
set(handles.text8,'visible','off')
set(handles.text10,'visible','off')
set(handles.text12,'visible','off')
set(handles.text13,'visible','off')
set(handles.edit11,'string',0,'visible','off')
grid off
cla% --- Executes during object creation, after setting all properties.function edit11_CreateFcn(hObject, eventdata, handles)% hObject handle to edit11 (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 edit11_Callback(hObject, eventdata, handles)% hObject handle to edit11 (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 edit11 as text% str2double(get(hObject,'String')) returns contents of edit11 as a double
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -