Multiplying each value of a vector with the corresponding value in another vector?
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Finn Farnan
am 13 Nov. 2020
Kommentiert: Star Strider
am 13 Nov. 2020
I have 4 vectors E,A,alpha,temp (each 21x1)
I want to carry out the following equation:
theta = E*A*alpha*temp [-1 ;1]
and theta be a vector where the first value is: theta(1) = E(1)*A(1)*alpha(1)*temp(1) * [-1;1]
and theta(n) = E(n)*A(n)*alpha(n)*temp(n) * [-1;1] etc.
Do I use for loop, how would I got about this?
Thank you in advance.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 13 Nov. 2020
Use element-wise multiplication. If all the other vectors are column vectors, the [-1 1] vector must be a row vector:
theta = E.*A.*alpha.*temp*[-1 1]
2 Kommentare
Weitere Antworten (2)
Setsuna Yuuki.
am 13 Nov. 2020
Bearbeitet: Setsuna Yuuki.
am 13 Nov. 2020
with loop for
for n = 1:length(E)
theta(:,n) = E(n)*A(n)*alpha(n)*temp(n) * [-1;1]
end
or can be:
theta(n) = E.*A.*alpha.*temp(n).*[-1;1]
2 Kommentare
Setsuna Yuuki.
am 13 Nov. 2020
Bearbeitet: Setsuna Yuuki.
am 13 Nov. 2020
My error in the code:
theta(n) = E.*A.*alpha.*temp(n).*[-1;1]
%is
theta= E.*A.*alpha.*temp.*[-1;1]
loop:
theta(:,n) = ...
Siehe auch
Kategorien
Mehr zu Optimization Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!