フィルターのクリア

trying to plot 2d graph with y=(x+some_​thing/x+sa​me_thing)

2 ビュー (過去 30 日間)
sumeet
sumeet 2017 年 9 月 30 日
コメント済み: Henry Giddens 2017 年 9 月 30 日
I want to plot multiple 2d graphs where x varies from 0 to 1 with step size of 0.1
y=(0.9*x+0.01)/(x+0.1);
when I run this i get y as variable containing just one value .
I was expecting an array of 11 values .
Why it did not happen ?
Also , if I wrote y=(x+2)/(x+2); I want y as array of ones . How can i do that ?
Thanks.

採用された回答

Henry Giddens
Henry Giddens 2017 年 9 月 30 日
編集済み: Henry Giddens 2017 年 9 月 30 日
You need to use the ./ command, instead of just /
y=(0.9*x+0.01)./(x+0.1)
/ by itself performs matrix division, whereas ./ performs element by element division
see help mrdivide and help rdivide for more information about the differences
  3 件のコメント
sumeet
sumeet 2017 年 9 月 30 日
編集済み: sumeet 2017 年 9 月 30 日
One more thing , if I want to make an array whose element is (1-entry_from_corresponding_element).*log(entry_from_corresponding_element)
Then , do I have to add . somewhere else in above ?
Henry Giddens
Henry Giddens 2017 年 9 月 30 日
No problem.
In general, if you want to do element-wise multiplication in matlab, then use the '.*' and './' notation. Both arrays should be either a single column or single row, or else you end up with an array that is nCols x nRows wide. You can of course do element wise multiplication and division on matrixes with any number of dimensions, as long as both are the same size.
If you want to do matrix multiplication and division, you should use the '*' and '/' functions without the dot. See the differences below:
[1 2; 3 4] .* [1 2; 3 4]
ans =
1 4
9 16
[1 2; 3 4] * [1 2; 3 4]
ans =
7 10
15 22
I see no reason why the notation you wrote wouldn't work
(1 - [1 2 3 4]).*log([1 2 3 4])
ans =
0 -0.6931 -2.1972 -4.1589

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by