Filter löschen
Filter löschen

I need to add and multiply a vetor

2 Ansichten (letzte 30 Tage)
Luis
Luis am 13 Dez. 2022
Kommentiert: Luis am 26 Dez. 2022
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 Kommentar
Torsten
Torsten am 13 Dez. 2022
And where is your code that doesn't work ?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Weitere Antworten (1)

Bora Eryilmaz
Bora Eryilmaz am 13 Dez. 2022
Bearbeitet: Bora Eryilmaz am 13 Dez. 2022
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

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by