problems writing a function

조회 수: 2 (최근 30일)
linofex
linofex 2015년 2월 25일
편집: linofex 2015년 2월 27일
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에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by