ode output function problem
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi,
I am using an output function for ode32s and I have a question regarding outputFcn.
Matlab ver 2018b,
On line 288 of ode32s:
feval(outputFcn,[t tfinal],y(outputs),'init',outputArgs{:});
On line 515 of ode32s however:
stop = feval(outputFcn,tout_new,yout_new(outputs,:),'',outputArgs{:});
Code is failing for too much input b/c in the latter there is one input missing with ''
Can you help me what's going on here?
採用された回答
Steven Lord
2019 年 5 月 16 日
As documented in the odeset function documentation page the function you specify as your custom OutputFcn must have a certain syntax and must accept certain types of calls.
"If you write a custom output function, then it must be of the form
status = myOutputFcn(t,y,flag)
The output function must also respond appropriately to these flags:"
You haven't provided much detail about the problem you're experiencing, but I suspect your custom OutputFcn does not conform to this requirement because it fails to accept the flag input argument.
7 件のコメント
It indeed conforms to the "initial" with 4 input variables (not 3)
feval(outputFcn,[t tfinal],y(outputs),'init',outputArgs{:});
And this is my function form:
myOutputFcn(t_tfinal, ysol_i, initTag, outputArgs)
I actually needed the forth input outputArgs, this "status = myOutputFcn(t,y,flag)" actually returns error "too man input arguments"
So, what is wrong with this anyways?
stop = feval(outputFcn,tout_new,yout_new(outputs,:),'',outputArgs{:});
Steven Lord
2019 年 5 月 16 日
Show your call to ode23 along with the code that defines your options structure containing your OutputFcn. My suspicion now is that you're passing additional parameters after the options structure which is supported for backwards compatibility with very old versions of MATLAB but is neither documented nor recommended any longer. The techniques described on this documentation page are the recommended ways to pass additional parameters into your ODE function, event functions, output functions, etc.
I am only passing parameters as following:
opts = odeset('RelTol',1e-6,'AbsTol',1e-10,'Stats','on','OutputFcn',@myOutputFcn);
[t_sol, y_sol] = ode23s(@BilMos10, [time_ext], [y0],opts, Params);
Params is a structure array.
I am not passing additionaly parameters. Do you see anything odd on the code above?
Steven Lord
2019 年 5 月 16 日
I am not passing additionaly parameters.
Yes you are, and you're using the undocumented and discouraged approach I mentioned. As written both BilMos10 and myOutputFcn must accept the Params struct array regardless of whether or not they use it. If only BilMos10 uses it, write your code like this instead so it doesn't get passed into myOutputFcn at all. Then myOutputFcn needs to accept only the three inputs t, y, and flag.
opts = odeset('RelTol',1e-6,'AbsTol',1e-10,'Stats','on','OutputFcn',@myOutputFcn);
[t_sol, y_sol] = ode23s(@(t, y) BilMos10(t, y, Params), time_ext, y0,opts);
If only myOutputFcn needs Params:
opts = odeset('RelTol',1e-6,'AbsTol',1e-10,'Stats','on','OutputFcn', ...
@(t, y, flag) myOutputFcn(t, y, flag, Params));
[t_sol, y_sol] = ode23s(@BilMos10, time_ext, y0,opts);
Ok, I tried this:
opts = odeset('RelTol',1e-6,'AbsTol',1e-10,'Stats','on','OutputFcn',@myOutputFcn);
[t_sol, y_sol] = ode23s(@(t, y) BilMos10(t, y, Params), time_ext, y0, opts);
myOutputFcn(t_tfinal, ysol_i, Tag)
It is still giving error at line 515 of ode23s (no error on line 288)
"Error using myOutputFcn
Too many output arguments."
Steven Lord
2019 年 5 月 16 日
This is a different problem than your original question. In the case where ode23s calls your output function with the '' flag, it must return an output telling ode23s whether or not to continue solving the ODE. From the documentation:
myOutputFcn must return a status of 0 or 1. If status = 1, then the solver halts integration. You can use this mechanism, for instance, to implement a Stop button.
Your myOutputFcn doesn't return anything, I assume?
Baha411
2019 年 5 月 17 日
Yes, my myOutputFcn function doesn't return anything.
Yes, status is needed.
Thanks for your help.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
製品
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
