number divided by vector

35 次查看(过去 30 天)
Yuji Zhang
Yuji Zhang 2014-11-9
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);

回答(4 个)

yonatan gerufi
yonatan gerufi 2014-11-9
编辑:yonatan gerufi 2014-11-9
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 个评论
Yuji Zhang
Yuji Zhang 2014-11-9
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!

请先登录,再进行评论。


yonatan gerufi
yonatan gerufi 2014-11-9
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 2014-11-9
编辑:Yuji Zhang 2014-11-9
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 2020-1-22
you can try
1./matrix

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by