完成以下四个目标
1、输入一阶电容电路参数,分析零状态、零输入、全响应过程;
2、输入一阶电感电路参数,分析零状态、零输入、全响应过程;
3、输入二阶动态电路参数,进行全响应分析;
4、用人机交互界面实现以上;
首先,我用的实现人机交互界面的开发工具是Matlab的GUI
我们先建立一个GUI界面
通过点击这个界面的七个选项,选择进入相应的交互界面
接下来我们分别建立这七个选项的GUI界面
以一阶RC零输入响应为例,我们建立静态文本表述可编辑文本框应该输入的数据,用滑动条滑动改变时间,在坐标轴绘出电容的电压曲线,建立两个文本框分别输出时间常数和指定时间的电压。
接下来给出代码
实现从第一个选择界面跳转到指定界面的一个按钮
function pushbuttonRC1_Callback(hObject, eventdata, handles)
h=gcf;
untitled15;%这里是你写的对应GUI代码的名称
close(h);
实现一阶RC零输入响应的GUI运行按钮(这里具体写一下代码对应GUI界面的操作)
str1=get(handles.editU,'String');%把输入U的文本框的tag改成editU,下面同理
str2=get(handles.editR,'String');
str3=get(handles.editC,'String');
str4=get(handles.editt1,'String');
str5=get(handles.editt2,'String');
str6=get(handles.editt3,'String');
U=str2double(str1);
R=str2double(str2);
C=str2double(str3);
t1=str2double(str4);
t2=str2double(str5);
t3=str2double(str6);
to=R*C;
str7=num2str(to);
set(handles.edit4,'String',str7);
t=t1:t3:t2;
Uc=U*exp(-t/to);
plot(handles.axes1,t,Uc);
title('一阶RC零输入响应');
ylabel('U/V');
xlabel('t/s');
t0=get(handles.slider5,'Value');%记得在GUI界面中把滑动条的max改成30,tag改成slider5
set(handles.editt,'String',t0);
u=U*exp(-t0/to);
str8=num2str(u);
set(handles.edit10,'string',str8);
实现任何一个按钮的停止命令
close
实现一阶RC零状态响应的GUI运行按钮
str1=get(handles.editU,'String');
str2=get(handles.editR,'String');
str3=get(handles.editC,'String');
str4=get(handles.editt1,'String');
str5=get(handles.editt2,'String');
str6=get(handles.editt3,'String');
U=str2double(str1);
R=str2double(str2);
C=str2double(str3);
t1=str2double(str4);
t2=str2double(str5);
t3=str2double(str6);
to=R*C;
str7=num2str(to);
set(handles.edit8,'String',str7);
t=t1:t3:t2;
Uc=U-U*exp(-t/to);
plot(handles.axes1,t,Uc);
title('一阶RC零状态响应');
ylabel('U/V');
xlabel('t/s');
t0=get(handles.slider5,'Value');
set(handles.edit11,'String',t0);
u=U*exp(-t0/to);
str8=num2str(u);
set(handles.edit10,'string',str8);
实现一阶RC全响应的GUI运行按钮
str1=get(handles.editUc,'String');
str2=get(handles.editUs,'String');
str3=get(handles.editR,'String');
str4=get(handles.editC,'String');
str5=get(handles.editt1,'String');
str6=get(handles.editt2,'String');
str7=get(handles.editt3,'String');
Uc=str2double(str1);
Us=str2double(str2);
R=str2double(str3);
C=str2double(str4);
t1=str2double(str5);
t2=str2double(str6);
t3=str2double(str7);
to=R*C;
str8=num2str(to);
set(handles.edit4,'String',str8);
t=t1:t3:t2;
U=Uc*exp(-t/to)+Us*(1-exp(-t/to));
plot(handles.axes1,t,U);
title('一阶RC全响应');
ylabel('U/V');
xlabel('t/s');
t0=get(handles.slider5,'Value');
set(handles.editt,'String',t0);
u=Uc*exp(-t0/to)+Us*(1-exp(-t0/to));
str9=num2str(u);
set(handles.edit10,'string',str9);
实现一阶RL零输入响应的GUI运行按钮
str1=get(handles.editI,'String');
str2=get(handles.editR,'String');
str3=get(handles.editL,'String');
str4=get(handles.editt1,'String');
str5=get(handles.editt2,'String');
str6=get(handles.editt3,'String');
str7=get(handles.edit7,'String');
Io=str2double(str1);
R=str2double(str2);
L=str2double(str3);
t1=str2double(str4);
t2=str2double(str5);
t3=str2double(str6);
to=L/R;
t=t1:t3:t2;
I=Io*exp(-t/to);
t0=str2double(str7);
I1=Io*exp(-t0/to);
set(handles.edit8,'String',I1);
u=R*Io*exp(-t/to);
plot(handles.axes1,t,I);
plot(handles.axes2,t,u,'r');
title('蓝线为电感电流曲线,红线为电感电压曲线')
实现一阶RL零状态响应的GUI运行按钮
str1=get(handles.editI,'String');
str2=get(handles.editR,'String');
str3=get(handles.editL,'String');
str4=get(handles.editt1,'String');
str5=get(handles.editt2,'String');
str6=get(handles.editt3,'String');
str7=get(handles.edit7,'String');
Io=str2double(str1);
R=str2double(str2);
L=str2double(str3);
t1=str2double(str4);
t2=str2double(str5);
t3=str2double(str6);
to=L/R;
t=t1:t3:t2;
I=Io-Io*exp(-t/to);
t0=str2double(str7);
I1=Io-Io*exp(-t0/to);
set(handles.edit8,'String',I1);
u=R*Io*exp(-t/to);
plot(handles.axes1,t,I);
plot(handles.axes2,t,u,'r');
title('蓝线为电感电流曲线,红线为电感电压曲线')
实现一阶RL全响应的GUI运行按钮
str1=get(handles.edit1,'String');
str2=get(handles.editIs,'String');
str3=get(handles.editR,'String');
str4=get(handles.editL,'String');
str5=get(handles.editt1,'String');
str6=get(handles.editt2,'String');
str7=get(handles.editt3,'String');
str8=get(handles.edit8,'String');
Io=str2double(str1);
Is=str2double(str2);
R=str2double(str3);
L=str2double(str4);
t1=str2double(str5);
t2=str2double(str6);
t3=str2double(str7);
to=L/R;
t=t1:t3:t2;
I=Io*exp(-t/to)+Is-Is*exp(-t/to);
t0=str2double(str8);
I1=Io*exp(-t0/to)+Is-Is*exp(-t0/to);
set(handles.edit9,'String',I1);
plot(handles.axes1,t,I);
title('一阶RL全响应');
二阶全响应
str1=get(handles.editU,'String');
str2=get(handles.editR,'String');
str3=get(handles.editC,'String');
str7=get(handles.editI,'String');
str8=get(handles.editL,'String');
Us=str2double(str1);
R=str2double(str2);
C=str2double(str3);
I=str2double(str7);
L=str2double(str8);
syms uc(t) il(t);
conduc = uc(0) == Us;
condil = il(0) == I;
ode1=diff(uc)==il/C;
ode2=diff(il)==-uc/L -R*il/L +Us/L;
odes=[ode1;ode2];
conds=[conduc;condil];
[ua(t),ia(t)]=dsolve(odes,conds);
ui(t)=Us-R*ia-ua;%计算电感两端电压
fplot(handles.axes1,t,ua);
hold on
fplot(handles.axes1,t,ui);
title('二阶全响应');
ylabel('U/V');
xlabel('t/s');
grid on
legend('电容电压','电感电压','Location','best')
我的公众号:北屿南诗,欢迎关注,干货不断!