# Linear equation solving in matlab

The Alchemist

## Homework Statement

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.

Last edited:

Gold Member

## Homework Statement

I have a matrix [10x11] which I want to solve (Ax=b).

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?

The Alchemist
Your system is underdetermined; you have more unknowns (11) than equations (10). This means that you already have an infinite number of solutions.
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

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?
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.

Gold Member
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.

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.

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.

#### Attachments

Gold Member
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.

#### Attachments

Last edited:
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,

Gold Member
But is it now a better idea to post this in a different forum? I have no clue.
Thanks again,

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