How to set lower and upper bound for only one of the output variable in lsqnonlin?
32 views (last 30 days)
Show older comments
In the documentation of lsqnonlin, following statement is written:
x = lsqnonlin(fun,x0,lb,ub) defines a set of lower and upper bounds on the design variables in x, so that the solution is always in the range lb ≤ x ≤ ub. You can fix the solution component x(i) by specifying lb(i) = ub(i).
How can we write this in case we want to make sure that at the end of optimization, specfic solution components are zero? Problem that I am solving is explained in detail below.
In the problem that I want to optimize, I am using an initial guess to find the location of zero (discontinuity edge) in a data using square root fitting which is not a perfect fit but a rather good guess for intial value (based on the problem and literature that I have read). Now, end goal of the optimization is to find the optimum location for the discontinuity edge. However, the function also has another lsqnonlin in it to find the coefficients around the discontinuity edge which is giving me 4x2 matrix. Values for coefficients at npower = -1 would go to zero at the discountinuity edge.
Is there a way to set the above condition in lower and upper bound for second lsqnonlin function? Attaching the code just in case someone wants to run the function. Following is the line that I used to run lsqnonlin
[cracktip,resnorm] = lsqnonlin(@(X)williamsctip(X,cracklinefit,coefs,v,u,rint,rext),200,170,sqrttip(counter2))
%200 is the initial guess while square root fitting gave us 210.5226. Using this as initial returns the same
%Ideally the edge should lie between 170 to 210.5226 so I selected these as lower and upper bounds.
I can't follow all of the details of what you presented but regarding your initial question:
How can we write this in case we want to make sure that at the end of optimization, specfic solution components are zero?
I would suggest just assigning lb(i) = 0 ub(i) = 0 for each of the components that should be held at zero
Edited: Jon on 4 Oct 2019
The lsqnonlin function expects a function, fun, which returns an [nx1] vector. You may need to make a new function that includes some intermediate steps, to reshape the array outputs of some of your functions into vectors, and returns a vector. You can use the reshape function for this purpose. Note MATLAB stores values columnwise, so if you reshape an array [a b;c d;e f;g h] into a vector the elements will be ordered a,c,e,g,b,d f, h
Actually if you just want to turn a 2-d matrix into a vector you can just use the colon operator.
For example if you have a 4x2 matrix called A, then v = A(:) will return a vector with the elements of A ordered columnwise
More Answers (0)
Find more on Matrix Indexing 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!