I am using this function
function maxh_d(t,x)
dxdt = zeros(2,1); % x(1) refers to x ,x(2) refers to p
dxdt(1)= -x(1) ; %+u
dxdt(2)= 2*x(1)*x(2);
end
in this code
[t_v,x_v] = ode23t(@(t,x) maxh_d(t,x), [0 10], [0.5 0.5]);
figure('Name','Nonlinear');
subplot(2,1,1)
plot(t_v, x_v(:,1));
I am getting this error
Error using maxh_d
Too many output arguments.
Error in mh_result>@(t,x)maxh_d(t,x) (line 1)
[t_v,x_v] = ode23t(@(t,x) maxh_d(t,x), [0 10], [0.5 0.5]);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode23t (line 143)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in mh_result (line 1)
[t_v,x_v] = ode23t(@(t,x) maxh_d(t,x), [0 10], [0.5 0.5]);

 採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 10 月 16 日

0 投票

Try to change your maxh_d function to explicitly return dxdt:
function dxdt = maxh_d(t,x)
dxdt = zeros(2,1); % x(1) refers to x ,x(2) refers to p
dxdt(1)= -x(1) ; %+u
dxdt(2)= 2*x(1)*x(2);
end
I've always written my ODE-functions so that they return the derivative. How you get that error-message I've no idea - since to my understanding 0 output arguments are one too few...
HTH

3 件のコメント

Stephen23
Stephen23 2020 年 10 月 16 日
編集済み: Stephen23 2020 年 10 月 16 日
"How you get that error-message I've no idea - since to my understanding 0 output arguments are one too few..."
The slightly ambiguous message is from the perspective of how the function is called, i.e. it is being called with more output arguments than the function can provide:
[X] = max(A); % okay
[X,Y] = max(A); % okay
[X,Y,Z] = max(A); % -> Too many output arguments.
If the function can provide zero outputs, then clearly requesting just one will be "too many".
Bjorn Gustavsson
Bjorn Gustavsson 2020 年 10 月 16 日
...Ah, perhaps I should spend some time reading and thinking before answering...
Stephen23
Stephen23 2020 年 10 月 16 日
編集済み: Stephen23 2020 年 10 月 16 日
@Bjorn Gustavsson: I agree that the message is ambiguous. Perhaps it should be expanded a little to clarify, e.g.: "Too many output arguments requested", or similar.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

質問済み:

2020 年 10 月 16 日

編集済み:

2020 年 10 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by