Hey need assistance solving third order system using ode45
1 次查看(过去 30 天)
显示 更早的评论
Hey trying to attempt this but still getting errors Code:
function output=funct(A,B,C,D,E,F,tmin,tmax)
[t,y]=ode45('func',[tmin tmax],[0 0 0]);
function ydot=func(t,y)
ydot(1)=y(2);
ydot(2)=y(3);
ydot(3)=((F*exp(-0.1*t)*cos(t))+(B*y(3))-(C*t*y(2))+(E*y(1)))/A;
ydot=ydot';
end
plot(t,y(:,1))
end
Error: >> func(1, 5, 7, 9, 11, 13, 0, 20)
Not enough input arguments.
Error in func (line 2)
[t,y]=ode45('func',[tmin tmax],[0 0 0]);
Error in odearguments (line 90)
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 func (line 2)
[t,y]=ode45('func',[tmin tmax],[0 0 0]);
0 个评论
回答(1 个)
Steven Lord
2018-4-26
Stop calling the ODE solvers with a char vector as the first input. That syntax still exists for backwards compatibility reasons but it behaves slightly differently than the syntax using function handles and hasn't been documented for probably 10-15 year now.
I strongly recommend using function handles instead. Once you switch to using function handles, you can have the ODE solver pass additional parameters into your ODE function using one of the techniques on this documentation page.
Usually if I'm trying to solve a simple problem in the Command Window I use the anonymous function approach. The nested function approach is good if you're writing one function file with a main function that calls the ODE solver and a local function that defines the ODE function as is the case for the problem you're trying to solve.
If you want a specific example you can use as a model for your code, see the "Pass Extra Parameters to ODE Function" example on the documentation page for ode45.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!