Effacer les filtres
Effacer les filtres

number divided by vector

20 vues (au cours des 30 derniers jours)
Yuji Zhang
Yuji Zhang le 9 Nov 2014
Hi everyone~ I divided a number by a vector and forgot to use ./ Why it didn't report error and gave me some result? What's the meaning of this calculation? Thank you!
t = (1: 0.5: 50)';
Carnot = 1-295/(500*exp(-0.02*t)+300);

Réponses (4)

yonatan gerufi
yonatan gerufi le 9 Nov 2014
Modifié(e) : yonatan gerufi le 9 Nov 2014
This is a tricky thing.
a. the command:
10/ [10,20]'
is equal (from matlab point of view) to:
[10;0]/ [10;20]
but the results will be just the non zeros line.
b. the command:
10/ [50,20]' (first element in denominator is larger)
is equal (from matlab point of view) to:
[0;10]/ [10;20]
but the results will be just the non zeros line.
  1 commentaire
Yuji Zhang
Yuji Zhang le 9 Nov 2014
Thanks Yonatan! I did some test and the results seem to be different...
clear;
t = (1: 3)';
y = exp(-0.02*t)+1;
c1 = 1/y;
c2 = [1 0 0]'/y;
Also do you know why 1/[1 2] yields error and 1/[1 2]' is legal? Let me know please. Thanks!

Connectez-vous pour commenter.


yonatan gerufi
yonatan gerufi le 9 Nov 2014
that's a good question, i believe both needs to be illegal.
how do you suggest matlab will understand the command:
1/[1,2]' ?
[1;0]/[1;2] or [1;1]/[1;2] or perhaps [0;1]/[1;2] ?
there is lack of clarity.
for better understanding i recommend reading on matrix divide. see for example: link 1,
if the previous answer answers your question you can do "accept answer" so people will know.
good luck!

Yuji Zhang
Yuji Zhang le 9 Nov 2014
Modifié(e) : Yuji Zhang le 9 Nov 2014
I think I figured out myself.
Division is defined by multiplication. For any A, B, and C, A/B = C means A = B*C.
Note B*C = C*B works for numbers, but not for vectors and matrices.
Think of x = 1/[1 2]'. What is x? It is something that satisfies x*[1 2]' = 1.
Without knowing the specific value, we know x is a row vector of length = 2, because only then x*[1 2]' will be a real number.
In fact
>> 1/[1 2]'
ans =
0 0.5000
>> [0 0.5]*[1 2]'
ans =
1
On the other hand
>> 1/[1 2]
Error using /
Matrix dimensions must agree.
Think of x = 1/[1 2], then x*[1 2] = 1, and there doesn't exist a solution. So it is illegal.
Note 1/matrix is called the inverse: 1/M = inv(M) There is a pseudo inverse pinv() that yields a best estimation for matrices that don't have an inverse, and also for vectors.
>> 1/[1 2]
Error using /
Matrix dimensions must agree.
>> pinv([1 2])
ans =
0.2000
0.4000
>> pinv([1 2]) * [1 2]
ans =
0.2000 0.4000
0.4000 0.8000
The answer is not 1. I think that's the best estimation by some algorithm.

Shoaib Waqar
Shoaib Waqar le 22 Jan 2020
you can try
1./matrix

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by