## There is an error in exp function but it doesn't tell what the error is?

### AYUSH KUMAR (view profile)

on 19 Mar 2019
Latest activity Commented on by Walter Roberson

### Walter Roberson (view profile)

on 20 Mar 2019
I have made a function which contains the following lines
D = Widths(n)/Precision ;
potl = Pots (n) + (V_a * q) - (xposl * Slope);
for l=1:Precision
potr = (potl - (D*Slope)) ;
if (mod(n,2)==1)
a = (sqrt(2*me_Al*(potl - Energy))/h_bar) ;
M(1,1)=exp(-a*D);
M(1,2)= 0 ;
M(2,1)= 0 ;
M(2,2)= exp(a*D) ;
else
I am using the function in this script
E=0:0.01:0.6;
T_E = rtd_te (0, E, 1);
semilogy(E,T_E);
But when I run the script it gives the error
Error in rtd_te (line 45)
M(1,1)=exp(-a*D);
Error in Test2 (line 2)
T_E = rtd_te (0, E, 1);
I have not initialised or defined the matrix M anywhere else.
Can anybody tell me why is the error coming and how I can rectify it??

Steven Lord

### Steven Lord (view profile)

on 20 Mar 2019
I don't think that's the full error message. Please copy everything displayed in red and everything displayed in orange (if anything) into a comment on this post. The exact and full text of the message may contain information that will help determine the cause of the problem you're experiencing.
AYUSH KUMAR

### AYUSH KUMAR (view profile)

on 20 Mar 2019
The full error is
Subscripted assignment dimension mismatch.
Error in rtTransmission (line 54)
M(1,1)=exp(-a*DivW);
Error in Test_t (line 2)
T_E = rtTransmission(0,En,1 );
Why is it showing assignment dimension mismatch even if i am assigning values element wise ?
Thank you for responding
Walter Roberson

### Walter Roberson (view profile)

on 20 Mar 2019
In your experience what is the difference between variables and matrices such that size(a) and size(D) somehow become meaningless concepts of no valid interest to people attempting to help you debug your program .

### Jos (10584) (view profile)

on 20 Mar 2019

Use
dbstop if error
and inspect the contents of the variables! You'll see what is wrong :-)

### Steven Lord (view profile)

on 20 Mar 2019

M(1, 1) refers to one element in M.
I suspect one of a and DivW is not a scalar (I'm guessing one of them is 1-by-61, the size of the E vector you created and passed into your rtd_te function as the second input argument.)
If my suspicion is correct that means exp(-a*DivW) will not be a scalar, it will likely be a 1-by-61 vector. Just like you can't fit a dozen eggs into one cup of an egg carton (at least not without breaking some eggs) you can't fit a dozen (or 61, or even just 2) elements from exp(-a*DivW) into that one element in M.

Walter Roberson

### Walter Roberson (view profile)

on 20 Mar 2019
You can easily fit a dozen eggs into one standard cup of a egg carton if the eggs are louse eggs.
(Sorry, I couldn't resist nit-picking.)