フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how can i fix this error "Subscript indices must either be real positive integers or logicals".in the following program?

1 回表示 (過去 30 日間)
ABHISHEK KUMAR
ABHISHEK KUMAR 2013 年 9 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
e1=input('enter the value of ei1') e2=input('enter the value of ei2') w=1.5:0.01:1.6; k1=0.25; k2=0.25; a=0.0005; ne=3.19; r=1.5*10^-6; l=2*pi*r; kn=(2*pi*ne*l)./w; b=sqrt(1-k1); c=sqrt(1-k2); f=sqrt(k1-k2); g=sqrt(-1)*kn*l; ed=e2((c-b*exp(-a.*l-g))./(1-b*c*exp(-a.*l-g)))+e1((-f*exp(a*l/2-g/2))./(1-b*c*exp(-a.*l-g))); y=abs(ed); z=y^2; plot(w,z)
  1 件のコメント
Jan
Jan 2013 年 9 月 13 日
If you format your code properly, the reading is much easier.
When you post the complete error message, we do not have to guess, where the problem occurs.

回答 (2 件)

Roger Stafford
Roger Stafford 2013 年 9 月 13 日
Your problem presumably occurs at the line
ed=e2(...) + e1(...);
If you intended e2 and e1 to be vectors, which is how matlab is interpreting them, the quantities inside the parentheses need to be real, positive integers since they are interpreted as indices, whereas you have complex fractional values there.
If you intended them to be some kind of function, your method of using 'input' for that purpose didn't achieve that. What kind of entities do you actually have in mind for e2 and e1 as a user input?

Image Analyst
Image Analyst 2013 年 9 月 13 日
Perhaps you meant:
ed=e2.*((c-b*exp(-a.*l-g))./(1-b*c*exp(-a.*l-g)))+e1.*((-f*exp(a*l/2-g/2))./(1-b*c*exp(-a.*l-g)));
Note, I don't know what values e2 took and what e1 took but for the values I plugged in, ed was complex and then it bombed at the z=y^2 line, so you might need to fix that too.
  2 件のコメント
ABHISHEK KUMAR
ABHISHEK KUMAR 2013 年 9 月 13 日
sir i have corrected the above mentioned error,but i am getting a straight line in the plot, desired plot is not coming.it should be gaussian beam . either e1=1,e2=0 or e1=0,e2=1. help me to correct this program.
Image Analyst
Image Analyst 2013 年 9 月 13 日
Do what people do in situations like this. Break your equation up into smaller terms and see what each one is like:
e1=0
e2=1
w=1.5:0.01:1.6;
k1=0.25;
k2=0.25;
a=0.0005;
ne=3.19;
r=1.5*10^-6;
l=2*pi*r;
kn=(2*pi*ne*l)./w;
b=sqrt(1-k1);
c=sqrt(1-k2);
f=sqrt(k1-k2);
g=sqrt(-1)*kn*l;
term1 = c-b*exp(-a.*l-g)
term2 = 1-b*c*exp(-a.*l-g)
ed=e2.*((c-b*exp(-a.*l-g))./(1-b*c*exp(-a.*l-g)))+e1.*((-f*exp(a*l/2-g/2))./(1-b*c*exp(-a.*l-g)));
y=abs(ed);
z=y.^2;
plot(w,z)
I don't think the line is straight. I think it's just that you are looking at such a small chunk of the curve that it looks straight over that really really small portion of it.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by