Is it possible to solve for a directly without using the inverse?

  • MATLAB
  • Thread starter feenaboccles
  • Start date
  • Tags
    Matlab
In summary: If you can find a way of rephrasing the problem so that the first term is replaced by a constant, then the problem can be solved directly.
  • #1
feenaboccles
3
0
I'm working on a project where the following has to be solved on a regular basis, as new column vectors are added to the matrix X.

a = x' * inv (X * X') * X

where
m is the number of examples
d is the dimensionality of the vector x
x is d x 1 and norm2(x) <= 1
X is d x m, consisting of m "x" vectors arranged column-wise (not row-wise as is typically the case)
and
a should be m x 1

I'm wondering is there a faster way to calculate in Matlab, other than a direct implementation of the above. It's not an equation in the usual form Xw = y, so the built-in solver won't work. I'm wondering are there any decompositions that might help, but bear in mind that the equation is solved, then X is changed, then we return to solve the equation once more for a different x.

Thanks
 
Physics news on Phys.org
  • #2
Why don't you write your own Matlab function?
 
  • #3
whs said:
Why don't you write your own Matlab function?

The code in my original post is Matlab code which does solve the equation. My question is not particularly Matlab-centric: it's whether the problem can be re-phrased, through some factorisation or decomposition, which would expedite its solution. Particularly, I'm wondering can it be rephrased in such as way that I can employ the heavily optimised solvers one finds in Matlab and various lin alg libraries like BLAS.
 
  • #4
Ah, I don't know the answer, but you might want to try posting this (or getting it moved) to the computers/math software section where there are lots of matlab/mathematica type questions.
 
  • #5
why don't you just take the transpose, then everything goes back to normal ?
 
  • #6
trambolin said:
why don't you just take the transpose, then everything goes back to normal ?

Actually it won't.

Take a standard linear regression problem
X * w = y
where
m is the number of training samples
d is the dimensionality of each training sample xm
X is m x d the datapoints xm arranged row-wise
y is m x 1
w is d x 1

The standard equations are (less regularization) are
w = inv(X' * X) * X' * y

Or

w' = y' * X * inv (X' * X)'

If you say Z = X' (i.e datapoints are arranged column wise, rather than row-wise), you get

w' = y * Z' * inv (Z * Z')'Now consider my example. In my example I'm expression a new datapoint as a linear combination (the vector a) of all previous datapoints. This is different to the standard regression problem. Hence, whereas w above is d x 1, a is m x 1. So, if we have a new datapoint z, and we want to express it as a linear combination of previous datapoints arranged column-wise in Z. We minimise ||a||2 subject to z = Z * a and thereby get

a = z' * inv (Z * Z') * Z

My question is is there any way of rephrasing this so the inverse can be avoided, and the problem solved directly.

The key diffence in the equations for a and w' is the first term, y is m x 1, but z is d x 1
 

1. How do I solve an equation in Matlab?

In Matlab, you can solve an equation using the "solve" command. This command takes in two arguments: the equation and the variable you want to solve for. For example, if you want to solve the equation x + 2 = 5 for x, you would use the command "solve(x + 2 == 5, x)".

2. What if I have multiple equations to solve?

If you have multiple equations to solve, you can use the "solve" command with a vector of equations. For example, if you have the equations x + y = 5 and 2x + 3y = 10, you would use the command "solve([x + y == 5, 2x + 3y == 10], [x, y])" to solve for the variables x and y.

3. Can I solve equations with complex numbers in Matlab?

Yes, Matlab has the ability to solve equations with complex numbers. You can use the "solve" command with complex numbers as long as you use the "i" symbol to represent the imaginary unit. For example, if you have the equation x^2 + 3i = 0, you would use the command "solve(x^2 + 3i == 0, x)".

4. What if I want to solve for a specific variable in an equation with multiple variables?

In this case, you can use the "solve" command with a specific variable as the second argument. For example, if you have the equation x + y + z = 10 and you want to solve for z, you would use the command "solve(x + y + z == 10, z)".

5. Is there a way to check if my solution for an equation is correct?

Yes, you can use the "subs" command in Matlab to substitute the solution back into the original equation and see if it holds true. For example, if you have the equation x + 2 = 5 and you solve for x to get x = 3, you can use the command "subs(x + 2 == 5, x, 3)" and if the result is true, then your solution is correct.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Differential Equations
Replies
2
Views
974
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top