- 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.
problems writing a function
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Stephen23
le 25 Fév 2015
Modifié(e) : Stephen23
le 25 Fév 2015
The difference is simple:
This is clearly explained in the documentation:
Réponse acceptée
Azzi Abdelmalek
le 25 Fév 2015
exp((abs((x+2).*(x-3))./((x+3).*(x-2))))
5 commentaires
Stephen23
le 26 Fév 2015
Modifié(e) : Stephen23
le 27 Fév 2015
"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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!