Problem with lsqnonlin: Optimization completed because the size of the gradient at the initial point is less than 1e-4 times the value of the function tolerance.

14 views (last 30 days)
Hi,
I have a function "fun103r" and it's output is "ER". I am transforming this function to an optimization expression using "fcn2optimexpr" to optimize "ER" with a coouple of variables including "k". The optimization variable is k (8x1). And to define extra (non-optimized) parameters, I'm using an anonymus function "f". Unfortunately, no iteration is performed when I try to use "lsqnonlin" and I receive this message: "Optimization completed because the size of the gradient at the initial point is less than 1e-4 times the value of the function tolerance".
I'll be glad if you could help.
clear;
clc;
%run('Fun103r');
Pa =216;
sp=7;
L=0.2;
Lb=[13.2 14.0 14.0 14.0 14.0 14.0 13.2];
N=zeros(sp);
ss=0;
E = 3.4342e10;
J = 0.9028 ;
na=6;
d1=[2.0 4.0 6.2 15.2 17.4 19.4];
opts = detectImportOptions('AppBR.xlsx');
Error using detectImportOptions
Unable to find or open 'AppBR.xlsx'. Check the path and filename or file permissions.
preview('AppBR.xlsx',opts);
opts.Sheet = 'D1-3BR';
opts.SelectedVariableNames = [1:9];
opts.DataRange = '2:484';
Rtr3=readmatrix('AppBR.xlsx',opts);
k = optimvar('k',8,1); % 8-by-1 optimization variable
[ER] = fcn2optimexpr(@Fun103r,k); % transformation of function "Fun103r"
k0=[100000; 200000; 100000; 200000; 200000; 100000; 200000; 100000]; % starting point for k
f = @(k)Fun103r(ss,Pa,sp,L,Lb,N,E,J,na,d1,k,Rtr3); % anonymus function to consider extra (non-optimized) parameters
options = optimoptions('lsqnonlin','Display','iter','FiniteDifferenceStepSize',1e-3);
options.StepTolerance = 1e-10;
options.Algorithm = 'levenberg-marquardt';
k=lsqnonlin(f,k0,options);
  4 Comments
Torsten
Torsten on 29 Jan 2023
Edited: Torsten on 29 Jan 2023
It's necessary that the functions ER you return to lsqnonlin from "Fun103r" are differentiable with respect to the parameters k. If statements and round commands are forbidden. So there is no hope you will get reasonable results for k.
Did you call Fun103r with your initial values for k and inspected the results returned from your function ?
Sinem Tola
Sinem Tola on 29 Jan 2023
Thank you, you are right. I've forgotten about the supported operations. That's why the nested function doesn't work either to pass extra parameters..And yes I've run Fun103r for far values and yes the error gets bigger. Then, it seems there's no optimizaiton solution using MATLAB.

Sign in to comment.

Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!