Matlab Vectors for optimization

조회 수: 1 (최근 30일)
MM
MM 2020년 11월 27일
댓글: Sulaymon Eshkabilov 2020년 11월 27일
I have three variables, A, B and C. Which are used to create a matrix such that:
Matrix = [A B C], the elements when added should be equal to or less than 20.
i.e A+B+C20. ... Condition (1)
However, A , B and C each must be greater than 1. .... Condition (2)
I need to create a list of such matrices that follow the above mentioned conditions.
Additional Detail. - The purpose of above matrix list.
I am going to use that list to run another program(P1 for instance), where A,B and C are my input and I will receive an output(O1), I desire to use the corresponding matrix that gives me max of that output(O1).

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020년 11월 27일
Easy solution would be to employ: randi([2, 13], Ntimes) to generate A, B, C; Sum them up: A+B+C; Compare the summation value against 20 to verify condition (1). Afterwards, you can perform the comparison of the summation values: A+B+C.
  댓글 수: 2
MM
MM 2020년 11월 27일
편집: MM 2020년 11월 27일
In this code randi([2, 13], Ntimes), shouldn't it be randi([2, 16], Ntimes), since A, B and C can take values from 2 to 16? Assuming A = 16, B and C needs to be greater than 1, therefore, only way is 16,2,2.
Also, what is Ntimes?
Also, I need the list to be in order, not any random values. Your help is appreciated. Thank you in advance. :)
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020년 11월 27일
Your condition (2): A> 1, B>1, C> 1, i.e. A+B+C >=6. And your condition (1): A+B+C<=20. Thus, randi([2, 13], Ntimes) should be randi([2, 16], Ntimes). Ntimes is how many data points you'd need to generate.
If they need to be in order, then you can generate them easily with:
A =2:16; B = A; C = A; % Row vectors
Note they are integers, you may need to generate them as a rational numbers as well, i.e.
A = (1.1:0.1:16)'; B = A; C = A; % Column vectors
Sum them up
Compare them against 20.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by