Matlab:除了我需要的ode45之外,其他ODE都在工作-为什么?

Matlab:除了我需要的ode45之外,其他ODE都在工作-为什么?,matlab,ode45,Matlab,Ode45,我有以下脚本: h=[0.01 0.05 0.1 0.5 1]; func = @(t, y) -2*y+t*sin(t); opts = odeset('Reltol',1e-13,'AbsTol',1e-14,'Stats','on'); f1_f2_matrix = []; sinus=@(t) t*(sin(t)); error2nd = zeros(length(h),1); errorInf = zeros(length(h),1); error2ndEuler = zeros(le

我有以下脚本:

h=[0.01 0.05 0.1 0.5 1];
func = @(t, y) -2*y+t*sin(t);
opts = odeset('Reltol',1e-13,'AbsTol',1e-14,'Stats','on');
f1_f2_matrix = [];
sinus=@(t) t*(sin(t));
error2nd = zeros(length(h),1);
errorInf = zeros(length(h),1);
error2ndEuler = zeros(length(h),1);
errorInfEuler = zeros(length(h),1);


for i=1:length(h)
t=0:h(i):10;
euler = zeros(length(t),1);
fun_builtin = zeros(length(t),1);
t_builtin = zeros(length(t),1);
results = zeros(length(t),1);


%matrix for A=-2 and given h=0.01
matrix=[ 1-1/2*h(i), (1/2-sqrt(3)/3)*h(i); 
        (1/2+sqrt(3)/3)*h(i), 1-1/2*h(i)];


    for n=2:length(t)
    B = [-2*results(n-1) + sinus(t(n-1)+(1/2-sqrt(3)/6)*h(i));
         -2*results(n-1) + sinus(t(n-1) + (1/2+sqrt(3)/6)*h(i))];

%system of equations solution

    f1_f2_matrix = matrix\B; 

    results(n) = (results(n-1) + h(i)*0.5*(f1_f2_matrix(1) + f1_f2_matrix(2))); 

%euler
    euler(n) = euler(n-1)+h(i)*func(t(n-1),euler(n-1));

   end

   %ode45
[t_builtin,fun_builtin] = ode45(func, t, 0, opts);

%y'=-2y+tsin(t) errors
error2nd(i)=norm(fun_builtin-results)/norm(fun_builtin); %root mean square error of my function
errorInf(i)=norm((fun_builtin-results), Inf)/ norm((fun_builtin), Inf); %maximum error of my function

error2ndEuler(i)=norm(euler-results)/norm(fun_builtin); %root mean square error of my function (euler)
errorInfEuler(i)=norm((euler-results), Inf)/ norm((fun_builtin), Inf); 
%maximum error of my function (euler)

end

figure 
semilogy(h, error2nd, h, errorInf,h, error2ndEuler, h, errorInfEuler)
title([{('Dependence of root mean square and maximum errors')}; {('from h-step and method of solving differential equation')}])
legend('root mean square error: Gauss-Legendre of 4th order','maximum error: Gauss-Legendre of 4th order method','root mean square error: Euler method', 'maximum error: Euler method', 'Location', 'southeast');
xlabel('step');
ylabel('error'); 

请从上面的代码块中考虑下面的行:

%ode45
[t_builtin,fun_builtin] = ode45(func, t, 0, opts);
如果我将其更改为
ode113
ode23
等,则生成该图形,但当我将其更改为
ode45
时,会出现错误:

Error using ode45
Too many input arguments.

Error in task1 (line 41)
    [t_builtin,fun_builtin] = ode45(func, t, 0, opts);

我可以更改什么使其完美工作?

您正在运行哪个版本的Matlab?这对我有用。我明白了

版本 ans=


如果您键入
editODE45
您会得到什么?它看起来像是由Mathworks或其他人制作的吗?i、 e.底部是否显示“%Copyright 1984-2017 The MathWorks,Inc.”?尝试删除选项并手动插入它们或其他内容。
1845 successful steps
5 failed attempts
11101 function evaluations
1845 successful steps
5 failed attempts
11101 function evaluations
1844 successful steps
4 failed attempts
11089 function evaluations
1845 successful steps
8 failed attempts
11119 function evaluations
1845 successful steps
9 failed attempts
11125 function evaluations
>> testodes
1845 successful steps
5 failed attempts
11101 function evaluations
1845 successful steps
5 failed attempts
11101 function evaluations
1844 successful steps
4 failed attempts
11089 function evaluations
1845 successful steps
8 failed attempts
11119 function evaluations
1845 successful steps
9 failed attempts
11125 function evaluations
'9.2.0.556344 (R2017a)'