number divided by vector

조회 수: 35 (최근 30일)
Yuji Zhang
Yuji Zhang 2014년 11월 9일
답변: Shoaib Waqar 2020년 1월 22일
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