Hi all, I'm trying to write a function, but I have some problems, this is the script:
exp((abs((x+2)*(x-3))/((x+3)*(x-2))))
But Matlab shows me an error:
Error using *
Inner matrix dimensions must agree.
So I changed all with .*( what is the difference? ) The plot shows me a straight line at 2,42 (as if I only copy the function on matlab command window), but If I copy the function on wolfram site, the result is as I expect. Why? Thanks in advance, Alessandro

1 件のコメント

Stephen23
Stephen23 2015 年 2 月 25 日
編集済み: Stephen23 2015 年 2 月 25 日
The difference is simple:
  • without the period follow the rules of linear algebra, as used in mathematics using matrices, for example * performs matrix multiplication.
  • with the period performs element-wise operations on the corresponding elements of the arrays, for example .* gives the Hadamard product.
This is clearly explained in the documentation:

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

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 2 月 25 日

0 投票

exp((abs((x+2).*(x-3))./((x+3).*(x-2))))

5 件のコメント

linofex
linofex 2015 年 2 月 25 日
oh, ./ thank you! problem solved. Can you explain me the difference between * and .*?
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 2 月 25 日
[1 2].*[3 4]
The result is a multiplication element by element
[1*3 2*4]
The multiplication
[1 2]*[3 4]
is not allowed, because the number of columns in the first matrix should be the same as the number of rows in the second
linofex
linofex 2015 年 2 月 25 日
so,when I work with parenthesis I must write .*? thank you!
Stephen23
Stephen23 2015 年 2 月 26 日
編集済み: Stephen23 2015 年 2 月 27 日
"when I work with parenthesis I must write .*"
No, because the difference between * and .* has nothing to do with the parentheses at all. Read the documentation to know why: both of these operations can be performed on matrices, so the fact that you create matrices with parentheses is completely irrelevant to which operation you use. The difference is in what they calculate.
linofex
linofex 2015 年 2 月 27 日
編集済み: linofex 2015 年 2 月 27 日
thank you for the documentation,solved the difference between * , or .* but why in my function, without matrices, there was the error?

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2015 年 2 月 25 日

編集済み:

2015 年 2 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by