Linear equation solving in matlab

In summary, the problem presented is a curve fitting or multiple regression problem with an 11x10 matrix. The system is over determined, with at least one row being a linear combination of the others. The solution was found using the "NMinimize" command in Mathematica, with constraints on the possible values of Xi. The resulting residual norm was larger than the minimum least squares solution, indicating that a reduced model may provide better results.
  • #1
The Alchemist
18
0

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.
thanks in advance.
 
Last edited:
Physics news on Phys.org
  • #2
The Alchemist said:

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?
 
  • #3
Thanks for your reply,
The Electrician said:
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].

[tex] \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}[/tex]

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.
Thanks in advance
 
  • #4
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
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
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,
 

Attachments

  • Reduced A.png
    Reduced A.png
    6.4 KB · Views: 453
  • lineareqn.txt
    3.1 KB · Views: 441
  • bvector.png
    bvector.png
    2.3 KB · Views: 502
  • #7
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

  • Constrained1.png
    Constrained1.png
    32.1 KB · Views: 625
  • Constrained2.png
    Constrained2.png
    33.8 KB · Views: 748
  • Constrained3.png
    Constrained3.png
    19.5 KB · Views: 511
Last edited:
  • #8
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
The Alchemist said:
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.
 

1. What is a linear equation?

A linear equation is an algebraic equation in which each term is either a constant or a constant multiplied by a single variable. It can be written in the form y = mx + b, where y is the dependent variable, x is the independent variable, m is the slope, and b is the y-intercept.

2. How do I solve a linear equation in MATLAB?

To solve a linear equation in MATLAB, you can use the \ (backslash) operator. For example, if you have the equation 2x + 3 = 9, you can solve for x by typing x = (9 - 3) / 2 into the command window. MATLAB will automatically calculate the value of x and assign it to the variable.

3. Can MATLAB solve systems of linear equations?

Yes, MATLAB has built-in functions for solving systems of linear equations. One way is to use the solve function, which takes in a system of equations and variables as arguments and returns the solution in a symbolic form. Another way is to use the linsolve function, which takes in a system of linear equations in matrix form and returns the solution as a vector.

4. How do I plot a linear equation in MATLAB?

To plot a linear equation in MATLAB, you can use the plot function. First, define the independent variable x and the equation y = mx + b with appropriate values for m and b. Then, use the plot function to create a graph. For example, plot(x, 2*x+3) will plot the linear equation y = 2x + 3 on a graph.

5. Can I use MATLAB to solve non-linear equations?

Yes, MATLAB has functions for solving non-linear equations as well. The fzero function can be used to find the roots of a single-variable non-linear equation. For systems of non-linear equations, you can use the fsolve function. These functions use numerical methods to approximate the solutions.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
846
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
2
Replies
48
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
953
Back
Top