fminunc stopped because it exceeded the function evaluation limit, options.MaxFunEvals = 100000 (the default value).

Hello, I have this discretized functional called F1 (objective multivariable function) and I need to minimize it. Then, I have used FMINUNC to find the minimizer function "x" (solution) and the value of the objective function evaluated in the solution. However, that error occurs. How can I solve i?
function y=F1(U, N)
N=1000;
y = 0;
d = 3/(N-1);
U(1)=2;
U(N)=3;
for j=1:N-2
y = y + (d/2)*((U(j)*(1+((U(j+1)-U(j))/(d))^2)^0.5)+(U(j+1)*(1+((U(j+2)-U(j+1))/(d))^2)^0.5));
end
y = y;
Then;
options = optimoptions(@fminunc,'Display','iter','Algorithm','quasi-newton');
fun = @F1;
v0= ones(1,1000);
[x,fval] = fminunc(fun,v0,options);
fval

댓글 수: 6

Are you sure you didn't make any typo?
And are you aware you could also do array operations and use sum?
N=1000;
d = 3/(N-1);
U=zeros(N,1);
U(1)=2;
U(N)=3;
j=1:N-2;
y = (d/2)*((U(j).*(1+((U(j+1)-U(j))/(d)).^2).^0.5)+(U(j+1).*(1+((U(j+2)-U(j+1))/(d)).^2).^0.5));
y=sum(y);
disp(y)
2.0000
Oh thank you, I don't think I explained it well. Actually I need to minimize that F1 discretized function. Then I have also used FMINUNC to find "fval" (the value evaluated in solution x)
options = optimoptions(@fminunc,'Display','iter','Algorithm','quasi-newton');
fun = @F1;
v0= ones(1,1000);
[x,fval] = fminunc(fun,v0,options);
fval
fun = @F1;
In this context, what is F1 ?
I do not see any input variable for the code you posted? Which variable is to be altered by fminunc when looking for a minima ?
The function that I need to minimize is called F1.
You (now) have
function y=F1(U, N)
N=1000;
Is there a reason why you overwrite N immediately inside the function?
It seems to me that it would make more sense for you to have
function y = F1(U)
N = length(U);
There is a minima of -infinity at careful combinations of 0 and -infinity .

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

카테고리

태그

질문:

2021년 3월 25일

답변:

2021년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by