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.
Related
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.
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 am doing a 5D data reconstruction from 5D noisy data. I am looking for any MATLAB codes or functions to calculate the SNR (in dB) in order to compare the noisy data with the original 5D data. Is there any way to do this using MATLAB?
Use: r = snr(x,y)
From Matlab documentation: r = snr(x,y) returns the signal-to-noise ratio (SNR) in decibels of a signal, x, by computing the ratio of its summed squared magnitude to that of the noise, y. y must have the same dimensions as x. Use this form when the input signal is not necessarily sinusoidal and you have an estimate of the noise.
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.
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 6 years ago.
Improve this question
Given a function f(t) in the time domain t. Its Fourier transform is F(w) in the frequency domain.
How can I change the Fourier transform in Fourier space w, e.g. how can I compute F(w)*w?
I have already done the Fourier transform on a signal x with FFT(x) but then how do I proceed to multiply the FFT(x) with w? I really don't know what to do here...
I understood that you dont know how to get w.
Assuming your signal is x(t) over a uniform grid t:
N = numel(x);
dt = t(2)-t(1);
df = 1/(N*dt); % the frequency resolution (df=1/max_T)
if mod(N,2)==0
f_vector = df*((1:N)-1-N/2);
else
f_vector = df*((1:N)-0.5-N/2);
end
w=f_vector;
answer = fftshift(fft(x)).*w;
There's a chance you need to multiply w with 2*pi or pi, I wasn't too careful so check and see what makse sense
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);