作业帮 > 综合 > 作业

通过ode15s求解非线性微分方程

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/30 15:20:46
通过ode15s求解非线性微分方程
求解方程(非线性微分方程).
建立如下:
i1*R1+L1*(di1/dt) + P2=P1
r1*C1*(dUc1/dt)+uc1=P2
Ct*(dUct/dt)=(P2-Uct)/Rt1 - Uct/Rt2
然后在Matlab中建立m文件(elec.m),如下:
function dy=elec(t,y,pt,p)
pt=[...time data...]
p=[...voltage data...]
dy=zeros(17,1);
p=interp1(pt,p,t);
dy(2)=-(R1/L1)*y(2)+(1/L1)*(-y(1)+p);
dy(3)=(1/(r1*C1))*(y(1)-y(3));
dy(4)=(1/Ct)*(((y(1)-y(4))/Rt1)-(y(4)/Rt2));
这里p=P1,y1=P2,y2=i1,y3=Uc1,y4=Uct;R1,L1,C1 和r1值都为已知.
然后在matlab,调用
[T,Y] = ode15s(@elec,[0 10],[0 0 0 0]);
求方程解.但通过运算后,与仿真结果不同,请问为什么?
再有,如果R1,L1,C1 和r1值为未知,那么再知道P2的值,怎样全局优化(global optimization)这4个参数?
求解电路连接如下
function solv(tspan,x0,type)
% argument
% tspan stands for time span
% if (type=='ode45') tspan must be within [0:1],otherwise the calulation will be time-consuming
% if (tpye=='ode15s') tspan is not limited,but the accuracy can be low
% see help ode45/15s for more information
% state variables
% x1=P
% x2=y
% x3=dy/dt
% state function
% dx1/dt=0.0437/4.6*sqrt(400000-x1)-1.59/4.6*(x1-101325)*x2^3+201*x3
% dx2/dt=x3
% dx3/dt=-0.1407/3877*x1-0.05/3877*x3+38003/3877
% type='ode15s';
% tspan=[0:0.01:4];
% x0 =[2,2,0];
if (type(1:5)=='ode45')
if (tspan(length(tspan))>5)
warning('ctrl+C to terminate');
end
[t,x]=ode45(@odefun,tspan,x0);
else
[t,x]=ode15s(@odefun,tspan,x0);
end
subplot(2,1,1),plot(t,x(:,1),'-'),title('P');
subplot(2,1,2),plot(t,x(:,2),'-'),title('y');
end
function dx=odefun(t,x)
dx=zeros(3,1);
dx(1)=0.0437/4.6*(400000-x(1))-1.59/4.6*(x(1)-101325)*x(2)^3+201*x(3);
dx(2)=x(3);
dx(3)=-0.1407/3877*x(1)-0.05/3877*x(3)+38003/3877;
end
你需要给求值区间和初值.