How can I multiply each row of 3 matrices individually?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone,
I have 3 matrixes to be multiplied. x[36,36],r[36,36],a[36x1].
What i wanna do is this;
x(1,1)*r(1,1)*ai(1)+x(2,1)*r(2,1)*ai(2)+....+x(35,1)*r(35,1)*ai(35)+x(36,1)*r(36,1)*ai(36) <=Kj*y(1)
x(1,2)*r(1,2)*ai(1)+x(2,2)*r(2,2)*ai(2)+....+x(35,2)*r(35,2)*ai(35)+x(36,2)*r(36,2)*ai(36)<=Kj*y(2)
...
x(1,36)*r(1,36)*ai(1)+x(2,36)*r(2,36)*ai(2)+....+x(35,36)*r(35,36)*ai(35)+x(36,36)*r(36,36)*ai(36)<=Kj*y(36)
This is what i wrote so far;
sum(x.*rij*ai,2)- Kj*y(:,1)<=0
this does what i want to do with the right side( Kj*y()) but the left side is the opposite what i want.
it does this;
x(1,1)*r(1,1)*ai(1)+x(1,2)*r(1,2)*ai(2)+....+x(1,35)*r(1,35)*ai(35)+x(1,36)*r(1,36)*ai(36)<=Kj*y(1)
hope this is clear. open to every suggestions. What i am looking for is only one line! Like the one i tried writing!
Thank you in advance!
0 commentaires
Réponses (3)
David Hill
le 11 Avr 2022
sum(x.*rij*ai)- Kj*y(:,1)<=0;%want to add columns (delete ,2)
3 commentaires
Star Strider
le 11 Avr 2022
Modifié(e) : Star Strider
le 11 Avr 2022
The part of this involving K and y is ambiguous.
It would help to know what
and y are, because it appears that Kis a vector, and y is a matrix, the columns of which are used to multiply K to test the inequality.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/960835/image.png)
x = randi(9,4)
r = randi(9,4)
a = randi(9,4,1)
z = (x .* r)' .* a
z_sum = sum(z,2)
K = 92;
y = randi(9,1,4)
Ky = K .* y
z_logical = z_sum <= Ky
z_logical = sum((x .* r)' .* a, 2) <= Ky % Single-Line Version
for k1 = 1:size(x,1) % This Checks To Be Certain That The 'z' Matrix Is Caclulated Correctly
for k2 = 1:size(x,2)
z(k2,k1) = x(k2,k1) * r(k2,k1) * a(k2); % Check
end
end
z
EDIT — (11 Apr 2022 at 17:48)
Changed ‘K’ to be a constant scalar, and ‘y’ to be a row vector.
Since ‘z_sum’ is a column vector, the result of the logical comparison with ‘Ky’ will be a logical matrix. If optimtool wants a scalar result, it will be necessary to do further processing on ‘z_logical’.
.
Torsten
le 11 Avr 2022
Modifié(e) : Torsten
le 11 Avr 2022
(x.*rij).' * ai - Kj*y <= 0
assuming that ai and y are column vectors.
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!