Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Optimization with function: lsqnonlin

Subject: Optimization with function: lsqnonlin

From: Toan Cao

Date: 27 Mar, 2013 21:48:17

Message: 1 of 3

Hi everyone,
I know there are many people who have uses function "lsqnonlin" for optimization. Currently, I am encountering a problem relating calculation of Jacobian matrix for this function.
My problem is described as follows:

I have a vector-value function F consists of n=1000 scale-value functions. Total variables for F is about m=700.
1) I define a mx1 symbolic array of symbolic variables: X=[X1; X2; ...; X700].
2) Then, i compute symbolic gradient : grad_F = jacobian(F,X).
3) After step 2, i have Jacobian matrix nxm of F in Symbolic Expression, for example
grad_F = [2*X1 +5*X7 - 35*X550;
               4*X12 + 56*X45;
              .....
               67*X1 - 45*X15*X17]
Now, if i want to obtain Jacobian matrix of F with a real variable y =[1; 2;...;700], how can i do ?
Of course, we can use "for loop" by running row by row of grad_F and replace a symbolic variable Xi by a respective real variable y(i) at each position in this matrix. Uhmm, It takes so long time to accomplish just for one time.

If you have any solution, please help me.
Thanks in advance,
Toan

Subject: Optimization with function: lsqnonlin

From: Alan_Weiss

Date: 28 Mar, 2013 12:37:03

Message: 2 of 3

On 3/27/2013 5:48 PM, Toan Cao wrote:
> Hi everyone,
> I know there are many people who have uses function "lsqnonlin" for
> optimization. Currently, I am encountering a problem relating
> calculation of Jacobian matrix for this function.
> My problem is described as follows:
>
> I have a vector-value function F consists of n=1000 scale-value
> functions. Total variables for F is about m=700.
> 1) I define a mx1 symbolic array of symbolic variables: X=[X1; X2;
> ...; X700].
> 2) Then, i compute symbolic gradient : grad_F = jacobian(F,X).
> 3) After step 2, i have Jacobian matrix nxm of F in Symbolic
> Expression, for example
> grad_F = [2*X1 +5*X7 - 35*X550; 4*X12 + 56*X45;
> .....
> 67*X1 - 45*X15*X17]
> Now, if i want to obtain Jacobian matrix of F with a real variable y
> =[1; 2;...;700], how can i do ?
> Of course, we can use "for loop" by running row by row of grad_F and
> replace a symbolic variable Xi by a respective real variable y(i) at
> each position in this matrix. Uhmm, It takes so long time to
> accomplish just for one time.
>
> If you have any solution, please help me.
> Thanks in advance,
> Toan

Take a look at some documentation on using symbolic variables with
Optimization Toolbox:
http://www.mathworks.com/help/optim/examples/using-symbolic-mathematics-with-optimization-toolbox-solvers.html
http://www.mathworks.com/help/optim/ug/symbolic-math-toolbox-calculates-gradients-and-hessians.html

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: Optimization with function: lsqnonlin

From: Toan Cao

Date: 28 Mar, 2013 17:29:07

Message: 3 of 3

Alan_Weiss <aweiss@mathworks.com> wrote in message <kj1dhf$hh5$2@newscl01ah.mathworks.com>...
> On 3/27/2013 5:48 PM, Toan Cao wrote:
> > Hi everyone,
> > I know there are many people who have uses function "lsqnonlin" for
> > optimization. Currently, I am encountering a problem relating
> > calculation of Jacobian matrix for this function.
> > My problem is described as follows:
> >
> > I have a vector-value function F consists of n=1000 scale-value
> > functions. Total variables for F is about m=700.
> > 1) I define a mx1 symbolic array of symbolic variables: X=[X1; X2;
> > ...; X700].
> > 2) Then, i compute symbolic gradient : grad_F = jacobian(F,X).
> > 3) After step 2, i have Jacobian matrix nxm of F in Symbolic
> > Expression, for example
> > grad_F = [2*X1 +5*X7 - 35*X550; 4*X12 + 56*X45;
> > .....
> > 67*X1 - 45*X15*X17]
> > Now, if i want to obtain Jacobian matrix of F with a real variable y
> > =[1; 2;...;700], how can i do ?
> > Of course, we can use "for loop" by running row by row of grad_F and
> > replace a symbolic variable Xi by a respective real variable y(i) at
> > each position in this matrix. Uhmm, It takes so long time to
> > accomplish just for one time.
> >
> > If you have any solution, please help me.
> > Thanks in advance,
> > Toan
>
> Take a look at some documentation on using symbolic variables with
> Optimization Toolbox:
> http://www.mathworks.com/help/optim/examples/using-symbolic-mathematics-with-optimization-toolbox-solvers.html
> http://www.mathworks.com/help/optim/ug/symbolic-math-toolbox-calculates-gradients-and-hessians.html
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Hi Alan Weiss.
Thanks for your links, they are very useful.

Toan

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us