我正试图编写一个简单的Matlab代码来建模一个弹丸。每当我试图运行代码时,都会看到一个错误,说明输入参数太多。我正在运行代码
model1(44.7,45)
function[] = model1(vel, angle)
close all;
tspan = [0 3];
x0 = [0; 0.915; vel*cos(angle); vel*sin(angle)];
[x] = ode45(@ball, tspan, x0);
function xdot = ball(x)
g = 9.81;
xdot = [x(3); x(4); 0; -g];
end
endError using model1/ball
Too many input arguments.
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options,
varargin);
Error in model1 (line 9)
[x] = ode45(@ball, tspan, x0);我希望你能给我任何建议!
发布于 2016-04-04 08:41:30
错误是(我过去多次犯的错误),您也必须传递自变量(在这种情况下,时间)。
function [t, x] = model1(vel, angle)
tspan = [0 3];
x0 = [0; 0.915; vel*cos(angle); vel*sin(angle)];
[t, x] = ode45(@ball, tspan, x0);
end
function xdot = ball(t,x)
g = 9.81;
xdot = [x(3); x(4); 0; -g];
end我修改了您的代码以返回解决方案和相应的时间步骤。此外,我将ball删除为嵌套函数。
https://stackoverflow.com/questions/36397436
复制相似问题