How can I solve this matrix question using for loop?
Mostra commenti meno recenti
Dear all,
There is a problem that I need to solve in the attached picture. First I defined the benefit matrix as A, and then I set up a for loop and tried to find the newly formed benefit matrices in the tables for each user from 1 unit of water to 8 units of water with this code. However, I think I'm making a math error because it's not giving the correct result. I need to calculate the benefits for each user and show the maximum and how many units of water should go to each user as a result. How can I do it?
clc;
clear;
close all;
A=[6 5 7;12 14 30;35 40 42;75 55 50;85 65 60;91 70 70;96 75 72;100 80 75]; %the matrix of benefits for each user
%for 3 users
for i=1:8
v(i)=A(i,3)
%for 2 users
for j=1:8
v(j)= A(j,2);
%for 1 user
for k=1:8
v(k)=A(k,1);
end
end
end

Risposta accettata
Più risposte (0)
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!