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
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

Baha411
Baha411 2019년 5월 16일
편집: Baha411 2019년 5월 16일
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
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.
Baha411
Baha411 2019년 5월 16일
편집: Baha411 2019년 5월 16일
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);
Baha411
Baha411 2019년 5월 16일
편집: Baha411 2019년 5월 16일
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
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
Baha411 2019년 5월 17일
Yes, my myOutputFcn function doesn't return anything.
Yes, status is needed.
Thanks for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

질문:

2019년 5월 16일

댓글:

2019년 5월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by