Multiple linear system, same solution [closed] - matlab

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I know how to solve the problem
Ax=B
with matlab, I just use mldivide to obtain x: x=A\B
But what if I have multiple basis A_i and multiple data B_i but the nature of the problem suggests me that the solution x must be the same for every i?

You could try stacking the A matrices and B vectors to obtain a larger least squares system. That is, form
A = (A_1)
...
(A_n)
and
B = (B_1)
...
(B_n)
and then solve
A*x = B
in the least squares sense
The solution x to such a system will be the value that minimises
Sum{ || A_i*x - B_i ||^2 }

If I understand correctly, this is an image "unmixing" problem, which requests the solution of a (highly) overdetermined system of W x H equations (image area) in K unknowns (number of end members).
One wants to solve
X1.U1ij + X2.U2ij + X3.U3ij = Vij
(assuming K=3) where i, j cover the whole image.
The standard solutions will be least-squares minimization, with two caveats:
if there are outliers the results canbe badly biased and robust methods should be preferred;
if this is really a mixture problem, then the coefficients are constrained to be positive and the question should be recast as a linear programming problem.

Related

Generation of coordinates from a range of values in matlab [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
distance = [10:.1:30];
norm_dist = normpdf(distance,20,2);
I am trying to generate x,y,z coordinates from the above range of normally distributed values but don't know how to do. Please help.
The normal_dist variable generates values in a normally distributed fashion. I want to use these values to randomly generate the x,y,z, coordinates values. The separate x,y,z values need to be generated not a 3-D array
If I understand your question correctly, you need to use meshgrid function as well
distance = [10:.1:30];
[X,Y,Z] = meshgrid(distance);
F = normpdf(X,20,2);
As a result you'll get 3d grid with those numbers
meshgrid() creates a matrix you can use for further calculations. Probably you will need to make normpdf dependent on X, Y, Z at the same time, e.g.
F = normpdf(X.^2+Y.^2+Z.^2,20,2)

Matlab - Incorrect dimensions for raising a matrix to a power [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Suppose we have a=60 and B=60. I am trying to calculate this area:
when I try this:
W = ((u^2)* cot(B) + (v^2 * cot(a))/8;
I get this error:
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers,
use '.^'.
How can I use u^2 in the right way?
If u and v are a vector, you should write u.^2 and v.^2 instead (an element-wise operator). When you write u^2 means u * u and it does not mean when u is not a squared matrix.
However, if they are vector, it is not meant for computing the value of W.

Matlab: equivalent of R's matrix multiplication (A %*% B)? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Working in Matlab with time-homogenous Markov Chains and looking to figure out how I can perform matrix multiplication in Matlab for matrix A, similar to R's matrix multiplication, i.e., A %*% A. It would be even better if I could perform A^n instead for a given n instead of having to use A %*% A %*% A, when n = 3, for example.
Any help is greatly appreciated!
First of all you can raise a Matrix to a power in MATLAB:
A ^ n = A * A * A * ... * A
Actually MATLAB uses pretty sophisticated algorithms behind the scene to accelerate this.
For example, if the Matrix is diagonalizable, MATLAB will use that to accelerate the calumniation.

Represent the similarity between many items in a nice manner MATLAB [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to brainstorm an idea in MATLAB with you guys. Given a matrix with many columns (14K) and few rows (7) where columns are items and rows features of the items, I would like to compute the similarity with all items and keep it in matrix which is:
Easy to compute
Easy to access
for 1., I came up with a brilliant idea of using pdist() which is very fast:
A % my matrix
S = pdist(A') % computes the similarity btw all columns very fast
However accessing s is not convenient. I prefer to access similarity between item i and j , e.g. using S(i,j):
S(4,5) % is the similarity between item 4 and 5
In its original definition, S is an array not a matrix. Is making it as an 2D matrix a bad idea storage-wise? Could we think about a cool idea that can help me find which similaity corresponds to which items quickly?
Thank you.
You can use pdist2(A',A'). What is returned is essentially the distance matrix in its standard form where element (i,j) is the dissimilarity (or similarity) between i-th and j-th pattern.
Also, if you want to use pdist(), which is ok, you can convert the resulting array into the well-known distance matrix by using the function squareform().
So, in conclusion, if A is your dataset and S the distance matrix, you can use either
S=pdist(A');
S=squareform(S);
or
S=pdist2(A',A');
Now, regarding the storage point-of-view, you will certainly notice that such matrix is symmetric. What Matlab essentially proposes with the array S in pdist() is to save space: due to the fact that such matrix is symmetric you can as well save half of it in a vector. Indeed the array S has m(m-1)/2 elements whereas the matrix form has m^2 elements (if m is the number of patterns in your training set). On the other hand, most certainly is trickier to access such vector whereas the matrix is absolutely straightforward.
I'm not completely sure to understand what your question is, but if you want to access S(i, j) easily then the function squareform is made for this:
S = squareform(pdist(A'));
Best,

How do i obtain only the first principal component in MATLAB? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
For certain measurements i need to obtain only the numeric value of the first principal component from the matrix. Can someone please tell me how do i go about it?
the most straight forward way is just to get the top eigenvector/value of your data's covariance matrix using eigs
say the data matrix x is N by D, or # of data by dimension of data
you can simply do
C = cov(X);
[V, D] = eigs(C, 1);
in fact, you can get the top k principal components by running
[V, D] = eigs(C, k);