Turn off display for fsolve during a loop

7 Ansichten (letzte 30 Tage)
Hoskins Lab
Hoskins Lab am 30 Nov. 2017
Kommentiert: Hoskins Lab am 1 Dez. 2017
I am using a loop function to perform fsolve on a matrix. I am adapting a script provided by another person which would be applied to one condition at a time and looping it so I can apply it to a set of 1,000 results. Here is how I have it set up:
Ap=bts2(:,1);
A1=(1+Ap.^2).^-1;
short2longratio=A1./(1-A1);
for v = 1:1:1000
kin(v,:) = fsolve('sigma54_kinetics_fit_values_r12_weight_ratio',[.01 .01 .005],[],0,bts2(v,3),bts2(v,2),short2longratio(v));
end
This means that I end up seeing the text for "Equation solved. ..." x1,000 when I run this loop. I tried the previously recommended answer to change the settings (see below), but it didn't work.
for v = 1:1:1000
opts = optimset('Diagnostics','off', 'Display','off');
kin(v,:) = fsolve('sigma54_kinetics_fit_values_r12_weight_ratio',[.01 .01 .005],[],0,bts2(v,3),bts2(v,2),short2longratio(v), opts);
end
By changing the end of "fsolve('sigma54..." from "...ratio(v));" to "...ratio(v), opts);" the script/function breaks. If I just have the line for "opts = optimset..." and the regular ending of the fsolve function the display appears x1,000. Any solution?
  1 Kommentar
dpb
dpb am 30 Nov. 2017
Doc for fsolve and optimset says to use <optimoptions> instead for everything except fzero, fminbnd, fminsearch, and lsqnonneg. Whether that'll fix the issue I don't know, but I'd certainly start there.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Alan Weiss
Alan Weiss am 1 Dez. 2017
Bearbeitet: Alan Weiss am 1 Dez. 2017
Your call uses an undocumented (but still supported) syntax for passing extra parameters.
Place your options into the third argument, the one that is currently [].
kin(v,:) = fsolve('sigma54_kinetics_fit_values_r12_weight_ratio',...
[.01 .01 .005],opts,0,bts2(v,3),bts2(v,2),short2longratio(v));
Also, don't set the options inside the loop, it is a time-consuming process. Set them before the loop.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Kommentare
Hoskins Lab
Hoskins Lab am 1 Dez. 2017
I tried your suggestion and ran the following:
Ap=bts2(:,1);
A1=(1+Ap.^2).^-1;
short2longratio=A1./(1-A1);
opts = optimset('Diagnostics','off', 'Display','off');
for v = 1:1:1000
kin(v,:) = fsolve('sigma54_kinetics_fit_values_r12_weight_ratio',[.01 .01 .005],opts,[],0,bts2(v,3),bts2(v,2),short2longratio(v));
end
I got the following error message:
Error using sigma54_kinetics_fit_values_r12_weight_ratio
Too many input arguments.
Error in fsolve (line 219)
fuser = feval(funfcn{3},x,varargin{:});
Error in LOOPTESTv3 (line 6)
kin(v,:) = fsolve('sigma54_kinetics_fit_values_r12_weight_ratio',[.01 .01
.005],[],0,bts2(v,3),bts2(v,2),short2longratio(v),opts);
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
Hoskins Lab
Hoskins Lab am 1 Dez. 2017
I read you answer wrong! When I corrected it and took out the extra "[]," it worked! Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by