필터 지우기
필터 지우기

I need to add and multiply a vetor

조회 수: 2 (최근 30일)
Luis
Luis 2022년 12월 13일
댓글: Luis 2022년 12월 26일
Given a vector u = (u1 + u2 + ... + un) make a funcition which gives u1*u2+u2*u3+...+un-1*un. Apply it to the vector u = cos(0:pi/20:pi)
  댓글 수: 1
Torsten
Torsten 2022년 12월 13일
And where is your code that doesn't work ?

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

채택된 답변

DGM
DGM 2022년 12월 13일
You mean something like this?
u = cos(0:pi/20:pi);
v = sum(u(2:end) .* u(1:end-1))
v = 9.8769

추가 답변 (1개)

Bora Eryilmaz
Bora Eryilmaz 2022년 12월 13일
편집: Bora Eryilmaz 2022년 12월 13일
This looks like the dot product of the subvectors u(1:n-1) and u(2:end):
u = cos(0:pi/20:pi); % Create the vector
p = u(1:end-1) * u(2:end)' % Use the dot product.
p = 9.8769

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by