Subscript indices must either be real positive integers or logicals how can I fix it?

3 ビュー (過去 30 日間)
fs
fs 2017 年 1 月 19 日
回答済み: fs 2017 年 1 月 19 日
I am trying to plot this equation but I get error message.
K=9*10^9; e= 1.6*10^-19; p=0.33*10^-10; Alpha=1.09*10^3;
r=10^-10*linspace(33,500,10 );
V(r)=-K*(e^2./r)+ Alpha*exp(-r./p);
whos
plot(r,v);

採用された回答

Walter Roberson
Walter Roberson 2017 年 1 月 19 日
You cannot fix it without changing what you are trying to do. You need to decide whether you are trying to define a formula for V(r), or if you are trying to assign V as an array of results. As a formula, you could have V(r) on the left hand side, but you would have had to not assign specific numeric values to r. If you are trying to assign V as an array of results, then you cannot use V(r) because you cannot index arrays at floating point numbers.
Your easiest fix would be
V=-K*(e^2./r)+ Alpha*exp(-r./p);
plot(r, V);

その他の回答 (1 件)

fs
fs 2017 年 1 月 19 日
Thank you very much for a quick respond and clear explanation.

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by