回 帖 发 新 帖 刷新版面

主题:帮我改改我的出错程序!!!!!!!!!

主程序:
clear all
clc
l=2000;
t=0:pi/l:2*pi;
for i=1:1:length(t)
  u0(1,i)=0;%t(1,i);
end

Y=rungekutta([1 0],u0,tn);
        
figure 
plot(t,u0);
figure
plot(t,Y(:,1),t,Y(:,2))
legend('X1','X2',0)
子程序1:
%rungekutta
function Y=rungekutta(y0,u0,tn)
    
    l=2000;
    h=20/l;
    Y(1,:)=y0;
  
    for n=1:1:l
      k1=parameter(Y(n,:),u0(1,n),tn(1,n));
      k2=parameter(Y(n,:)+0.5*h*k1,u0(1,n),tn(1,n));
      k3=parameter(Y(n,:)+0.5*h*k2,u0(1,n),tn(1,n));
      k4=parameter(Y(n,:)+h*k3,u0(1,n),tn(1,n));
      Y(n+1,:)=Y(n,:)+(1/6)*h*(k1+2*k2+2*k3+k4);
  end
子程序2:
%parameter15
function k=parameter(x,tn)
  
  k(1,1)=x(1,2);
  k(1,2)=sin(tn);

回复列表 (共1个回复)

沙发

错误提示呢?

我来回复

您尚未登录,请登录后再回复。点此登录或注册