problems writing a function

1 次查看(过去 30 天)
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
exp((abs((x+2).*(x-3))./((x+3).*(x-2))))
  5 个评论
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 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by