%证明一阶RC电路中,任一点切线的横坐标差值A(t2-t1)等于时间常数τ
%swu_ly
%初始设值
clear,clc%清空数据与指令行
U=1;R=40;C=1;%假设电压U为1伏,电阻R为40欧,电容为1法拉
t0=0;%取t0=0秒切切线
t1=randi(150);%取t1为1到150以内的值做切线
syms t;%声明变量t
u(t)=U*exp(-t/R*C); %syms声明要和函数一起,不然会报错
u0=u(t0);
u1=u(t1);
f(t)=diff(u(t));%求导求斜率
k=f(t1);
k0=f(t0);
t=(0:1:150);
y0=k0*t+u0;%切线
y=k*(t-t1)+u1;
t2=fzero(@(t)k*(t-t1)+u1,[0,150]);%通过该切线与x坐标轴的交点计算出t2
tao=fzero(@(t)k0*t+u0,[0,150]);;%tao为τ,通过该切线与x坐标轴的交点计算出τ
plot(t,u(t),'r',t,y,'b',t,y0,'g'),ylim([0,1]);%画图
line([t1,t1],[0,u1],'color','k','linestyle','--');
line([0,t1],[u1,u1],'color','k','linestyle','--');
hold on; %保持当前的图与坐标轴属性,以便后续的绘图命令添加到现有的图表中
grid on
plot(0,1,'.','Color','g','MarkerSize',20);
plot(tao,0,'.','Color','g','MarkerSize',20);
plot(t2,0,'.','Color','b','MarkerSize',20);
plot(t1,u1,'.','Color','b','MarkerSize',20);
plot(t1,0,'.','Color','b','MarkerSize',20);
text(t1,u1,'切点')
text(t1,u1,'切点')
text(t1,0,'t1')
text(t2,0,'t2')
text(tao,0,'τ')
title('证明一阶RC电路中,任一点切线的横坐标差值A(t2-t1)等于时间常数τ示图')
legend('u(t)=U*exp(-t/R*C)','y=k*(t-t1)+u1','y0=k0*t+u0','Location','North')%最后‘'Location','North'’是位置
%进行判断
A=t2-t1;%A为t2-t2的差值
tf = isequal(A, tao)%判断A与τ是否相等,输出逻辑判断,为1则证明成功,为0则证明失败
有点小bug,希望大家谅解,恳请大佬修改指正,谢谢大家