# Homework Help: Linear equation solving in matlab

1. Mar 23, 2010

### The Alchemist

1. The problem statement, all variables and given/known data
I have a matrix [11x10] which I want to solve (Ax=b). Matlab comes with an answer, but I would like to know if there is a possibility to give boundary conditions to this problem. like x_i can't be greater than 300 or something. is it possible to restrict the outcome?

2. The attempt at a solution
I can't find any possibilities in the help.. and I can't think of anything to restrict the problem.
thanks in advance.

Last edited: Mar 23, 2010
2. Mar 23, 2010

### The Electrician

Your system is underdetermined; you have more unknowns (11) than equations (10). This means that you already have an infinite number of solutions.

Do you want all the x_i to be less than 300 (for example), several of them, or all of them?

Do you want 0 < x_i < +300, or -300 < x_i < +300?

The infinite number of solutions I mentioned earlier are exact solutions; the residual can be zero.

When you add the constraints you are contemplating, the residual may not be zero. What size residual can you accept?

3. Mar 23, 2010

### The Alchemist

Thanks for your reply,
I'm sorry, I kind of messed up. I meant 11 rows and 10 columns.. so that makes [11x10].

$$\begin{pmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,10} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,10} \\ \vdots & \vdots & \ddots & \vdots \\ a_{11,1} & a_{11,2} & \cdots & a_{11,10} \end{pmatrix}$$

Is it then still possible?
Well I know matlab has a result but with "out of bound" values, which I would like to restrict

Yeah it should be |x_i|<300
And residual size.. order of magnitude of 10^-2 would be nice.

I'm sorry I messed up the first assumption. Hope it is clear now.
Thanks in advance

4. Mar 23, 2010

### The Electrician

This is somewhat reminiscent of a linear programming problem.

But what you have is not quite that.

If you can post a link to a free hosting site with an image of your "A" matrix and your "b" vector, along with csv file of those items, I'll have a look at the problem.

Or, PM me with those attachments.

5. Mar 23, 2010

### Staff: Mentor

Since the matrix has 11 rows and 10 columns, the system is overdetermined, and this means that at least one row is a linear combination of the others.

6. Mar 24, 2010

### The Alchemist

Thanks for your replies, I really appreciate it.
I attached 3 files. one picture of the reduced A matrix, with only the 6 highest values of the matrix. one of the b vector. And the data files which include the full A matrix, the reduced and the b vector.

Thanks is advance,

#### Attached Files:

File size:
7.8 KB
Views:
134
File size:
3.1 KB
Views:
70
• ###### bvector.png
File size:
3.2 KB
Views:
151
7. Mar 24, 2010

### The Electrician

I hope I got all the numbers into Mathematica correctly. I calculated a least squares solution which is shown in the first image. You might check it against what Matlab gives. Also give a quick look over at the data in my image.

To solve this system with constraints, I used a command "NMinimize" in Mathematica. It can minimize nonlinear functions.

In the second image you can see in the NMinimize command that I have an expression for the norm of the residual. I calculated it as the matrix product of A times a vector of Xi minus the vector b, then took the Frobenius norm. There's a variable named Bound and you can see the 10 constraints of the Xi to be between -Bound and +Bound. The result of this command is a list in curly braces {}. The first number is the norm of the residual, followed by a list of the Xi values.

Looking at the least squares solution from the first image, we see that the largest Xi, namely X4, is 19007.1. One would think that if we allow NMinimize to search for a minimum with Bound set to slightly larger than X4, it should find a solution (essentially) equal to the least squares solution. This is what it did.

In the third image, I had NMinimize find solutions for several values of Bound. I also used the plot function to plot the value of the residual norm for a range of values of Bound from 300 to 20000. It gets a little noisy as Bound approaches 20000 because I limited the number of iterations in the search so I could get some results today instead of waiting till next week. There's a lot of number crunching involved in that plot!

As you can see, the attainable residual norm when you constrain Bound to be small is substantially larger than the minimum of the least squares solution.

You posted this in the homework help forum; is this actually a homework problem? It looks like a curve fitting problem to me. I calculated the condition number of your A matrix. It's shown in the second image as the ratio of the largest to the smallest singular value, a fairly large condition number of about 36000, even though the matrix itself has a fairly small norm.

If this is a curve fitting problem, or perhaps a multiple regression problem, you may get better results with a reduced model.

#### Attached Files:

File size:
60.5 KB
Views:
169
File size:
47.6 KB
Views:
206
• ###### Constrained3.png
File size:
32.5 KB
Views:
159
Last edited: Mar 24, 2010
8. Mar 25, 2010

### The Alchemist

Thank you for your efforts, I really appreciate it. And essentially it's not a 100% homework problem. It's just a problem I'm trying to solve. Your numbers are correct and your solution for the least square approximation is +- my matlab solution. Your last image looks very promising, with restrictions to the solution, I will have a look at that solution.
But is it now a better idea to post this in a different forum? I have no clue.
Thanks again,

9. Mar 25, 2010

### The Electrician

I think it's ok to leave it here. If a moderator thinks otherwise, they will move it.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook