Levenberg–Marquardt algorithm with fixing the last row of solution

Hi all, I am using Levenberg–Marquardt algorithm to do an optimization(I use lsqnonlin function). In fact I want to get a solution that I fix its last row. In fact my solution has this following forme :
X=[ x11 x12 x13 x14 ;
x21 x22 x23 x24 ;
x31 x32 x33 x34 ;
0 0 0 1 ]
So I want to get a solution using Levenberg–Marquardt with fixing its last row to [0 0 0 1] Any help please ?

 Accepted Answer

g = @(x) YourFunction( reshape([reshape(x, 3, 4); 0 0 0 1], [], 1) )
then optimize g

3 Comments

Accepted.
Although, I think the 2nd reshape must be omitted if YourFunction() expects matrix input.
YourFunction should not expect matrix input:
"fun is a function that accepts a vector x and returns a vector F, the objective functions evaluated at x"
"If the user-defined values for x and F are matrices, they are converted to a vector using linear indexing."
I think that's a mis-phrasing. In the following example, the objective expects matrix input and it works just fine
>> X=lsqnonlin( @(X) X-eye(3) , 2*eye(3))
This is also consistent with the more general link on Matrix Inputs, which says
When x0 is a matrix, solvers pass x as a matrix of the same size as x0 to both the objective function and to any nonlinear constraint function.

Sign in to comment.

More Answers (1)

Hi Walter, Thank you for your reply. Can you explain more your solution? why two functions reshape?

1 Comment

lsqnonlin passes in a vector. You need to make that vector into 3 x 4 so that you can paste on a bottom row. Then you make it a column vector again. The new output would look like
old(1,1)
old(2,1)
old(3,1)
new 0
old(1,2)
old(2,2)
old(3,2)
new 0
and so on, so it is not a simple manner of appending some values on to the end of it. The double reshape is the easiest way to inject the values in the places they are needed.

Sign in to comment.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!