ode output function problem
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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일
0 개 추천
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?
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
