Help in implementing ode45 in app designer

2 次查看(过去 30 天)
methods (Static)
function dydt = odefun(app,t3,Y,A)
dydt = 0;
dydt = A+2*t3;
end
end
properties (Access = public)
t = 0:0.005:20;
initial_x=2;
A=0;
t1=0; x=0;
end
methods (Access = private)
% Button pushed function: Button
function ButtonPushed(app, event)
[app.t1,app.x] = ode45(@(t,Y) app.odefun(t,Y,app.A), app.t, app.initial_x);
plot(app.UIAxes,app.t1,app.x,'-o');
end
end
This is my sample code. If I save the same function (odefun) as a separate file in the current directory, this code works. However, if I include the same function as methods (Static), I get the following error: 'Not enough input arguments...'. I remember, I read somewhere, that the parameters need to be initialized, which I have done. Still the code does not work. Any help in this regard will be appreciated. Thank you!

回答(1 个)

J. Alex Lee
J. Alex Lee 2020-3-9
Static methods don't assume that the app is passed as the first argument, so remove "app" from the arg list
methods (Static)
function dydt = odefun(t3,Y,A)
dydt = 0;
dydt = A+2*t3;
end
end

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by