Semilog function problem, cannot get a figure
2 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone, I have trouble with plotting part b) with the semilog graph.
When I changed my variable E to 1:2*20^-20. It also gives me no figures.
Thank you for your help. I appreictae it very much!
0 件のコメント
採用された回答
Steven Lord
2019 年 10 月 31 日
When you use the syntax "f(E) = something" with a numeric array E you're trying to set the elements of f whose indices are stored in E to some value. Because of this, something like:
f(1.5) = 42;
won't work because there's no such thing as the 1.5th element of an array.
On lines 10 and 21 you don't need to index into the left-hand side. It worked on line 10, but added a lot of unnecessary 0 entries.
x = [1 5 13 72 999];
y = x.^2;
y2(x) = x.^2;
whos y y2
y2 is much longer than y, but only five elements of y2 (elements 1, 5, 13, 72, and 999) actually have any useful data.
figure
plot(x, y)
figure
plot(x, y2(x))
Those two plots should look the same, but if even one element in x had not been a positive integer value the first approach would have worked but the second wouldn't have worked.
There's at least one additional issue with what you wrote. Look at E.
E = 2*10^-40:2*10^-20
When you try to create a vector using the colon operator : like A:B that tries to create a vector whose elements go from A to B in steps of 1.
x = 5:8 % [5, 5+1 (or 6), 6+1 (or 7), 7+1 (or 8)]
How many steps of 1 does it take to get from 2*10^-40 to 2*10^-20?
Were you trying to create a vector like [2*10^-40, 2*10^-39, 2*10^-38, ... 2*10^-21, 2*10^-20]? To do that you'll need either to use logspace instead of : or use : to generate the series slightly differently.
E = 2*10.^(-40:-20)
E = 2*logspace(-40, -20, 21)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!