我遇到了一阶微分方程的问题。我试图用ode23和ode23s来解决它们。微分方程是:
y' - z - u = 0
z' - u - y = 0
你' - y - z = 0
初始值为:y(0) = –1, z(0) = 1, u(0) = 0
。
我还想将它与ANALYTICAL解决方案进行比较:
y = - exp(x)
z = exp(x)
u = 0
我想这样做,因为我需要进行比较才能选择更好的求解器:ode23或ode23s,无论哪一个更接近解析解。
我的代码是:
%y'=z+u
%z'=u+y
%u'=y+z
%y(0)=-1,z(0)=1, u(0)=0 inital values
%y=y(0) z=y(1) u=y(2)
function dy = part1(t,k)
y=k(1);
z=k(2);
u=k(3);
dy=[z+u;u+y;y+z];
和
%comparıson of numerıcal and analytıcal equatıons
%Fırst comparıson functıon
[t1,y1]=ode23('part1',[0 16],[0 1 -1]);
%Second comparıson functıon
[t2,y2]=ode23s('part1',[0 16],[0 1 -1]);
%ya,za,ua are analytıcal equtıons
ya =(-exp(t1));
za=exp(t1);
ua=0;
%ı have to plot ya,ua and za depends on ode23 and ode23s
%then ı wıll decıde the best solutıon depends on my shape
%either ode23 or ode23s ıs the best?
plot(t1,ya,t1,za,t1,ua);title('ya,za,ua')
figure
plot(t1,y1(:,1),t1,y1(:,2),t1,y1(:,3));title('ode23')
figure
plot(t2,y2(:,1),t2,y2(:,2),t2,y2(:,3));title('ode23s')
但它不起作用。有人能帮助我吗?