do matrix multiplication by taking different values according to the range

A matrices :
2 1 3
7 1 3
2 8 6
5 9 4
B matrix: C matrix: D matrix:
0,1 0,4 0,6
0,7 0,1 0,5
0,8 0,5 0,6
E matrix :
10
20
15
(from the second row, i.e. except the first row)For values between 1 ,2,3 in matrix A, matrix B is checked.
For values 4, 5,6 in matrix A, matrix C is checked.
For values between 7,8,9 in matrix A, matrix D is checked.
For the 7 value written in the 2nd row of the A matrix (since it is between 5 and 9) the D matrix is checked. The value in the 2th row of the D matrix is taken. (the value of 0.6 is taken) (We got the value in row 2 because in the first row of matrix A, cell (1,1) it says 2)
Then it will look at the top number in the A matrix, for example 7 in the second row. For example, it writes 2. Since it writes the value 2, it takes the value 20 in the 2nd row in the E matrix.
Then 0.5 multiplied by 20. And this is used for all values in matrix A.
new matrix:
0,5*20 0,1*10 0,8*15
0,7*20 0,6*10 0,5*15
0,5*20 0,6*10 0,5*15
If we multiply these values, we get the following matrix:
new matrix:
10 1 12
14 6 7,5
10 6 7,5
Thank you for help !

10 Comments

What does this mean: "(from the second row, i.e. except the first row)For values between 1 ,2,3 in matrix A, matrix B is checked."?
I do not understand any sentence of the description. What does "checking a matrix" mean? Does B contain 2 columns or does "0,1" mean 0.1 ? What exactly is "0,5*20"? [0, 100], or 10? Please use dots as decimal points. Commas have a different meaning in Matlab.
Post the input data in valid Matlab syntax. Then we can use them by copy&paste.
What is your question?
My native language is not English and I don't know much about matlab, so my apologies.I will try to explain it again.
I want to get new matrix by using A, B, C, D, E matrices.
The first row of matrix A must be examined to obtain the new matrix.For example, matrix A has the value 2 in the first row. So let's take the second column value from matrix E.Then it is necessary to take the second row value from one of the B, C, D matrices and multiply the two values. Well, when choosing one of B, C, D, the value of cell A (1,1) is important.If it is 1,2 or 3 in cell A (1,1), we multiply the value in row 2 in matrix B with the value in row 2 in matrix E and write it in cell (1,1) in matrix.
If it is 4,,5 or 6 in cell A (1,1), we multiply the value in row 2 in matrix C with the value in row 2 in matrix E and write it in cell (1,1) in matrix.
If it is 7,8 or 9 in cell A (1,1), we multiply the value in row 2 in matrix D with the value in row 2 in matrix E and write it in cell (1,1) in matrix.
And I want to get the new matrix by performing all these steps.
If I were to correct my example:
A matrices :
2 1 3
7 1 3
2 8 6
5 9 4
B matrix: C matrix: D matrix:
0.1 0.4 0.6
0.7 0.1 0.5
0.8 0.5 0.6
E matrix :
10
20
15
new matrix:
10 1 12
14 6 7.5
10 6 7.5
Thank u for help !
Thanks for trying it again. It is no problem for the readers in this forum, if some questions for clarifications are required. This is a typical part of solving a problem.
Let me summarize:
A = [2 1 3; ...
7 1 3; ...
2 8 6; ...
5 9 4];
B = [0.1; 0.7; 0.8];
C = [0.4; 0.1; 0.5];
D = [0.6; 0.5; 0.6];
E = [10; 20; 50];
Yes and I want to create new matrix using these matrices.
new-matrix = [10 1 12; ...
14 6 7,5;...
10 6 7.5 ]
I've read your explanations 10 times and they are still confusing. E.g. A is a [4 x 3] matrix and the wanted output is a [3 x 3] matrix only. For "2 1 3" matrix B shoudl be used, but the result contains "0.5, 0.1, 0.8" multiplied elementwise by E([2,1,3]). But "0.5, 0.1, 0.8" is not found in B?!
I cannot imagine, for which kind of problem this code could be a solution.
Then let me tell you about the logic of the code I want to create.
I'm working on genetic algorithm so I use matlab.
It says 2,1,3 in the first column of matrix A. They are the products that I produce in my factory. second product, first product and third product. I randomly determine which machine will produce these products. You can see this in rows two, three, and four of matrix A. For example, I produced the second product in matrix A on 7,2,5 machines.
I can produce these products on any machine. However, the times vary depending on the machine I produce. The duration matrix is ​​B, C, D matrices. If I generated on the 1,2 and third machine I use the times in matrix B. If I produced on the 4th and 6th machine, I take into account the times in the C matrix. If I produced on the 7,8 and ninth machine, I take into account the times in the D matrix. So I actually divided the machines into three groups.
Finally, there is this. I can see how many of the products I will produce in the E matrix. For example, I can see in matrix E that I will produce 10 of the second product. I want to find out the total production time by multiplying the number of products by the production time of the products.
For example, the first product was produced in the first machine. The durations of the first product are in the first row of the B, C, D matrix. Since it was produced on the first machine, I take the value in the first row in matrix B. It says I will produce 10 products in the E matrix. So by multiplying 10 by 0.1, I get 1 total production time.
To give another example, it seems that the third product was produced on the third machine. Since it is produced on the third machine, I get the value of the third row in the B group. (The production times of the third product are in the third row in the B,C,D matrix) (It says 0.8)
For the number of products, I look at the third row in the E matrix. (writes 15)
I multiply 0.8 by 15 to get the total time. I get the value 12.
I hope I was able to explain. So far I haven't figured out how to do this, I hope there is a way.
Thank you for your interest
@Berfin Çetinkaya: Actually the computations should take some lines of code only, but the description is such complicated that my brain is fried. The complexity is growing.
So I recommend to restart from scratch. Avoid talking about "machines" and "products", because for Matlab these are all numbers.
A = [2 1 3; ...
7 1 3; ...
2 8 6; ...
5 9 4];
B = [0.1; 0.7; 0.8];
C = [0.4; 0.1; 0.5];
D = [0.6; 0.5; 0.6];
E = [10; 20; 15];
Most likely it is easier to combine B, C, D to one matrix F = [B,C,D].
Now you want to get:
R = [0.5*20, 0.1*10, 0.8*15; ...
0.7*20, 0.6*10, 0.5*15; ...
0.5*20, 0.6*10, 0.5*15]
According to your explanations, the factors [20, 10, 15] are obtained by:
E(A(1, :));
Does this mean, that the other 3 rows of A do not matter here?
But then I understand your explanations such, that the other factors are taken from B, because the values of the row of A are in the range [1,2,3]. But 0.5 is not an element of B?! So where does the factor 0.5 in the element R(1,1) come from?
Why does R have 3 rows, while A has 4?
Yes, you're right, it got very complicated. I think I should have asked the question properly from the beginning. I will open a new question. Thank you for helping.

Sign in to comment.

Answers (0)

Categories

Asked:

on 25 May 2022

Commented:

Jan
on 26 May 2022

Community Treasure Hunt

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

Start Hunting!