필터 지우기
필터 지우기

Multiply the vector organs

조회 수: 2 (최근 30일)
Eran Shvartzman
Eran Shvartzman 2017년 12월 27일
편집: John D'Errico 2017년 12월 27일
How to multiply the vector parts without using a prod function
For example: s=[1 2 3 4], v=24

답변 (2개)

John D'Errico
John D'Errico 2017년 12월 27일
편집: John D'Errico 2017년 12월 27일
You want to multiply s*v, so perform that multiplication, but without using the * operator? May I ask why you want to do such a silly thing, instead of just doing s*v?
As long as one of them is a scalar, then conv will suffice.
conv(s,v)
It will be slower, less efficient. It will serve absolutely no purpose.
(See the comments in case I was wrong in interpreting the ambiguous question.)
  댓글 수: 5
Matt J
Matt J 2017년 12월 27일
편집: Matt J 2017년 12월 27일
Note that this survives even if one of the elements of s is zero.
So, incidentally, does exp(sum(log(s))).
>> v=exp(sum(log([0,1,2,3])))
v =
0
Negative numbers work, too.
John D'Errico
John D'Errico 2017년 12월 27일
Good point!

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2017년 12월 27일
편집: Matt J 2017년 12월 27일
for i=1:4
v=exp(sum(log(s)));
end
  댓글 수: 1
John D'Errico
John D'Errico 2017년 12월 27일
You may be right here. the request may be to write v=prod(s), without use of prod, instead of forming the product s*v.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by