how to generate a matrix from another matrix

2 ビュー (過去 30 日間)
Naema
Naema 2014 年 6 月 20 日
コメント済み: Andrew 2014 年 6 月 20 日
Hi: I am having a matrix called "alpha" with size (1x50) and another matrix called "beta" which is related to alpha through the following relation: beta=0.001/alpha I wanted to get beta as another "1x50" matrix so the number "0.001" contributes to all the values in the matrix "alpha". can any one help me out with this? Naema

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 6 月 20 日
beta = 0.0001./alpha
  4 件のコメント
Naema
Naema 2014 年 6 月 20 日
so I needed alpha to go from 11 to 3 not from 3 to 11.
Andrew
Andrew 2014 年 6 月 20 日
Naema, what do you mean by inverse? If you want the element wise inverse such as
1/alpha_ij
then you would use
r=log(0.001)./(-(alpha.^(-1));
If you want alpha flipped, as in you defined alpha as linspace(3,11,50) but actually want linspace(11,3,50) then you can use the fliplr function like this:
r=log(0.001)./(-fliplr(alpha))
If you want the matrix inverse of alpha, well that's impossible to actually find (you can do some funny things with pseudo inverses but they're not real inverses).
If none of that is what you are looking for then you need to ask a new question and better define what it is you are looking for.
Andrew

サインインしてコメントする。

その他の回答 (2 件)

AJ von Alt
AJ von Alt 2014 年 6 月 20 日
You can use rdivide to do this. "rdivide" will expand the scalar "0.001" to match the size of alpha and perform elementwise division.
alpha = 1:50;
beta = 0.001./alpha;
  1 件のコメント
Naema
Naema 2014 年 6 月 20 日
thanks, I am sorry just noted your reply!

サインインしてコメントする。


Andrew
Andrew 2014 年 6 月 20 日
Hello Naema. There is a really simple solution to this. All you have to do is use element operations by adding a dot.
For instance:
A=randn(50); %generating a random 50x50 matrix
B=0.001./A; %note the dot before the slash.
The reason you need the dot is because when you use something/(a matrix) in matlab, it assumes that you are trying to solve a linear system. By adding in the dot you tell matlab that instead you want to perform the operation of 0.001/A for each element of A. This notation works for many operations as well.
For instance say you want to multiply all of the elements two matrices together. Then we could do:
A=randn(50);
B=randn(50);
C=A.*B;
Here the result C would be the element multiplication of matrices A and B. That is c_ij=a_ij*b_ij. Note that this is much different than usual matrix multiplication.
There are other operators this applies to as well, such as the exponential operator and the likes. It is very useful!
  1 件のコメント
Naema
Naema 2014 年 6 月 20 日
thanks for the explanations!.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by