inv Matrix must be square

how to invert alpha in the following relation.so if alpha values are from 3 to 11 with 50 steps (size of alpha is "1x50"), how can do the following:
r=log(0.001)./(-inv(alpha));
I got the following error: Error using ==> inv Matrix must be square.

1 个评论

It is not clear what operation you're trying to achieve. Since alpha is not square, inv(alpha) is indeed undefined.

请先登录,再进行评论。

回答(1 个)

Andrew
Andrew 2014-6-20
编辑: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).
Hope one of these is what you are looking for.
Andrew

8 个评论

I meant the second case; I needed to flip the numbers in alpha so the max becomes the minimum and vise versa.
I applied your solution: r=log(0.001)./(-fliplr(alpha))
but I had this error:
Error using ==> mtimes
Inner matrix dimensions must agree.
I am not sure how that could happen because there is not any multiplication. In addition, the following code works just fine on my machine:
alpha=linspace(3,11,50);
r=log(0.001)./(-fliplr(alpha));
can you copy and paste the output from:
whos alpha
and then maybe we can figure out what is going on.
Naema
Naema 2014-6-20
编辑:Matt J 2014-6-20
alpha is a .mat file whose size is 1x50. it contains some values resulted from previous calculations.
here is my code, please help me:
load etae.mat
load Ceff10.mat
load h_Au.mat
lambda=1310e-9;
c=3*10^8;
v=c/lambda;
load neff1
alpha=imag(neff1);
h=6.626e-34;
l10=log(0.001)./(-fliplr((alpha)*(2*pi)/1310e-9));
a=(Ceff10).*etae*1.6e-19/h/v;
r10=(1-exp(-fliplr(alpha)*(2*pi)/1310e-9)*l10))*a;
plot(h_Au,l10,'r','linewidth',2);
try
l10=log(0.001)./(-fliplr(alpha).*(2*pi()/lambda));
that really shouldn't change anything unless you somehow have made pi a matrix. I can't really confirm anything else since I don't have your .mat files. If you still can't get it you could upload these and then I could trouble shoot more. Another option would be to write the command:
dbstop if error
in the command line in matlab and then try to run your code. When you encounter the error you should have access to all of the variables that MATLAB at that time. At that point if you enter :
whos
into the MATLAB command line and post the output I might be able to help you some but again the easiest way would be to just attach the mat files to a comment.
by the way, the plot command can be: plot(h_Au,l10,'r','linewidth',2); or: plot(h_Au,r10,'r','linewidth',2); please let me know what happens with you asaaaap! thanks, Naema
Hey, so the issue is in the r10 line.
you need to add dots to make it
r10=(1-exp(-fliplr(alpha)*(2*pi())/1310e-9).*l10).*a;
However you still have a problem because the data you have is generating INF values from this code because the exponents are too large. Unfortunately that's not something I can help you with. You probably have a typo in your code or have misinterpreted an equation, so you'll have to check that out.
Sorry for the late response. I got sidetracked by somehting.
Andrew

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

提问:

2014-6-20

评论:

2014-6-21

Community Treasure Hunt

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

Start Hunting!

Translated by