MATLAB Newsgroup

Dear All,

I want to find an optimal solution for a linear set of equations with more unknowns than equations, ultimately up to 3 equations and some 4-10 variables.

Lets start simple with 2 equations, 3 unknowns

coefficient matrix:

A=[1 1 0; 0 0 1];

b = [10;10];

Solution represent a set of forces which have a certain upper limit, e.g.: ub=[20 20 20];

I do the following:

1. find particular solution:

Fp = A\b;

2. find null solution:

F0 = null(A);

Now all possible solutions are given by:

F = Fp + F0 * const

and the target is to find a constant which gives an optimal solution. Optimal I define as follows:

We are talking about force equilibrium, F represent forces which have a certain maximum (ub) and minimum (lb).

My solution is optimal if the sum of the square of the ratios F/Fmax is minimal:

obj = sum( (F./ub).^2 )

In this simple example it is easy to hand-calculate that this is obtained with F = [5 5 10]

I use optimisation tool fmincon. For the F0 multiplier "const" I add a new variable to my solution and add a column of zeros to A which gives Aeq.

Using the following piece of code:

>>>

%%%Add zeros after A

Aeq(:,numF+1:numX) = 0;

beq = b;

x0=[0; 0; 0; 0];

options = optimset('LargeScale','off');

[x,fval,exitflag,output] = fmincon(@(x) Fobjfun(x, Fp, F0, ub),x0,[],[],Aeq,beq,lb,ub,[],options)

>>>

With Fobjfun:

>>>function obj = Fobjfun(x, Fp, F0, ub)

x(1:3) = Fp(i) + F0(i)*x(4);

obj = sum( (x(1:numF)./ub(1:numF)).^2 );

>>>

This works, it gives the answer: x=[5;5;10;-7.0711] and obj 0.375.

Next:

I lower one constraint:

ub = [4; 20; 20]

Now I get the answer:

>>>

x =

3.9255

6.0745

10.0000

-13.5982

obj =

0.4904

>>>

Verification by simply trying a range of possible C's (x4) shows indeed that x4 shall be -13.5982 and the corresponding obj value is 0.4904. However the corresponding forces are not gives in x(1:3). I have to add a final line which reconstructs forces as is done in the objective funtion. This seems strange to me. x4 does not correspond with x1:x3. If I reconstruct forces with F=Fp + F0 * x4 than a set of forces is given which is differnt from x1-x3 but gives the correct (and indeed optimal) objective value.

Questions:

1. Anyone understands what is going wrong here? Or is it not going wrong?

2. Anyone has better ideas in finding the optimal solution from a set of linear equations with more unknowns than equations?

Any help is greatly appreciated,

Mark

"Mark " <markcouwenberg@atgmaildot.com> wrote in message <ganstp$1je$1@fred.mathworks.com>...

> Dear All,

>

> I want to find an optimal solution for a linear set of equations with more unknowns than equations, ultimately up to 3 equations and some 4-10 variables.

> Lets start simple with 2 equations, 3 unknowns

> coefficient matrix:

> A=[1 1 0; 0 0 1];

> b = [10;10];

>

> Solution represent a set of forces which have a certain upper limit, e.g.: ub=[20 20 20];

>

> I do the following:

> 1. find particular solution:

> Fp = A\b;

> 2. find null solution:

> F0 = null(A);

>

> Now all possible solutions are given by:

> F = Fp + F0 * const

>

> and the target is to find a constant which gives an optimal solution. Optimal I define as follows:

> We are talking about force equilibrium, F represent forces which have a certain maximum (ub) and minimum (lb).

> My solution is optimal if the sum of the square of the ratios F/Fmax is minimal:

> obj = sum( (F./ub).^2 )

> In this simple example it is easy to hand-calculate that this is obtained with F = [5 5 10]

>

> I use optimisation tool fmincon. For the F0 multiplier "const" I add a new variable to my solution and add a column of zeros to A which gives Aeq.

> Using the following piece of code:

> >>>

> %%%Add zeros after A

> Aeq(:,numF+1:numX) = 0;

> beq = b;

> x0=[0; 0; 0; 0];

> options = optimset('LargeScale','off');

> [x,fval,exitflag,output] = fmincon(@(x) Fobjfun(x, Fp, F0, ub),x0,[],[],Aeq,beq,lb,ub,[],options)

> >>>

> With Fobjfun:

> >>>function obj = Fobjfun(x, Fp, F0, ub)

> x(1:3) = Fp(i) + F0(i)*x(4);

> obj = sum( (x(1:numF)./ub(1:numF)).^2 );

> >>>

>

> This works, it gives the answer: x=[5;5;10;-7.0711] and obj 0.375.

> Next:

> I lower one constraint:

> ub = [4; 20; 20]

>

> Now I get the answer:

> >>>

> x =

>

> 3.9255

> 6.0745

> 10.0000

> -13.5982

> obj =

>

> 0.4904

> >>>

> Verification by simply trying a range of possible C's (x4) shows indeed that x4 shall be -13.5982 and the corresponding obj value is 0.4904. However the corresponding forces are not gives in x(1:3). I have to add a final line which reconstructs forces as is done in the objective funtion. This seems strange to me. x4 does not correspond with x1:x3. If I reconstruct forces with F=Fp + F0 * x4 than a set of forces is given which is differnt from x1-x3 but gives the correct (and indeed optimal) objective value.

> Questions:

> 1. Anyone understands what is going wrong here? Or is it not going wrong?

> 2. Anyone has better ideas in finding the optimal solution from a set of linear equations with more unknowns than equations?

>

> Any help is greatly appreciated,

>

> Mark

>

>

Dear All,

I found the solution. The reason I use a multiplier for my null solution is the way I previously "solved" these kind of problems: simply by trying a huge range of possibilties of multipliers. However using decent optimisation technology this is unnecessary. I can enter my coefficient matrix directly as Aeq. There is no need for adding an extra variable for every null space vector. So now my code would be:

>>>

A = [1 1 0 0 0;...

0 0 1 1 1;...

1 -1 0.5 1 -1];

beq = [10;10;10];

ub = [20; 20; 20; 20; 20];

lb = [-20; -20; -20; -20; -20];

Aeq = A;

x0=[0; 0; 0; 0; 0];

options = optimset('LargeScale','off');

[x,fval,exitflag,output] = fmincon(@(x) Fobjfun(x, ub),x0,[],[],Aeq,beq,lb,ub,[],options)

>>>

and the objective function:

>>>

function obj = Fobjfun(x, ub)

obj = sum( (x./ub).^2 );

>>>

This works. However I am still curious about what happens in the previous posted method. Any ideas?

Brgds,

Mark

You can think of your watch list as threads that you have bookmarked.

You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.

To add items to your watch list, click the "add to watch list" link at the bottom of any page.

To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.

You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.

To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.

To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.

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.

The newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.

Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.

Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using open-standard protocols. No single entity “owns” the newsgroups.

There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.soft-sys.matlab newsgroup.

**MATLAB Central**

You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.

Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.

**One Account**

Your MATLAB Central account is tied to your MathWorks Account for easy access.

**Use the Email Address of Your Choice**

The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.

**Spam Control**

Most newsgroup spam is filtered out by the MATLAB Central Newsreader.

**Tagging**

Messages can be tagged with a relevant label by any signed-in user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.

**Watch lists**

Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.

- Use a newsreader through your school, employer, or internet service provider
- Pay for newsgroup access from a commercial provider
- Use Google Groups
- Mathforum.org provides a newsreader with access to the comp.soft sys.matlab newsgroup
- Run your own server. For typical instructions, see: http://www.slyck.com/ng.php?page=2