Program to Change the least number of a given Matrix Elements to get a condition on the sum of the numbers from collated row digits of the Matrix
I have a given Matrix A=k x n (k rows and n columns), with all elements digits in base 4,(can be only {0,1,2,3}). I want to write a program to change for any input matrix A to a new output B matrix respecting a condition. The condition is to change the least number of elements of A to form a modified matrix B(which keeps all the other unchanged elements of A), such that the k numbers of the row collated digits summed in base 4, are a multiple of (4^n)-1, expressed in base 4(n the number of columns of A and B)(The multiple must be the one such that B differs with the minimum nr of elements from A). Note that (4^n)-1 in base 4 is a row of n digits all 3s(3333…33, n times) . (4^3)-1 in base 4 = 333, However, a multiple of (4^3)-1, for instance [5*(4^3)-1] in base 4= 10323.
%I will give just an Example of a matrix A=3×6, k=3, n=6
A= [3,3,3,2,2,2; 3,2,3,3,1,2; 3,1,0,1,3,2]
%Convert row collated digits to numbers then to decimal
base2base(‘333222’,4,10)
base2base(‘323312’,4,10)
base2base(‘310132’,4,10)
%ans = ‘4074’
%ans = ‘3830’
%ans = ‘3358’
%Calculate their sum in base 10 of row digits 3 numbers
S=4074+3830+3358
%S = 11262
%Calculate (4^6) – 1 in decimal
(4^6) – 1
%4095
% One can see that a multiple of 2 of (4^6) – 1=8190, which can be expressed in base 4 , and is close to S
base2base(‘8190’,10,4)
%ans = ‘1333332’
%To get this row digits sum just one element change is sufficient, change element of A (2,1)=3 to B(2,1)=0, hence B is
B= [3,3,3,2,2,2; 0,2,3,3,1,2; 3,1,0,1,3,2]
base2base(‘333222’,4,10)
base2base(‘023312’,4,10)
base2base(‘310132’,4,10)
%ans = ‘4074’
%ans = ‘758’
%ans = ‘3358’
%Sum all in decimal to check if it is in base 4
S2=4074+758+3358
%S2 = 8190
% Which is the sought result. The program should be able to do such conversions of A to B for any input AI have a given Matrix A=k x n (k rows and n columns), with all elements digits in base 4,(can be only {0,1,2,3}). I want to write a program to change for any input matrix A to a new output B matrix respecting a condition. The condition is to change the least number of elements of A to form a modified matrix B(which keeps all the other unchanged elements of A), such that the k numbers of the row collated digits summed in base 4, are a multiple of (4^n)-1, expressed in base 4(n the number of columns of A and B)(The multiple must be the one such that B differs with the minimum nr of elements from A). Note that (4^n)-1 in base 4 is a row of n digits all 3s(3333…33, n times) . (4^3)-1 in base 4 = 333, However, a multiple of (4^3)-1, for instance [5*(4^3)-1] in base 4= 10323.
%I will give just an Example of a matrix A=3×6, k=3, n=6
A= [3,3,3,2,2,2; 3,2,3,3,1,2; 3,1,0,1,3,2]
%Convert row collated digits to numbers then to decimal
base2base(‘333222’,4,10)
base2base(‘323312’,4,10)
base2base(‘310132’,4,10)
%ans = ‘4074’
%ans = ‘3830’
%ans = ‘3358’
%Calculate their sum in base 10 of row digits 3 numbers
S=4074+3830+3358
%S = 11262
%Calculate (4^6) – 1 in decimal
(4^6) – 1
%4095
% One can see that a multiple of 2 of (4^6) – 1=8190, which can be expressed in base 4 , and is close to S
base2base(‘8190’,10,4)
%ans = ‘1333332’
%To get this row digits sum just one element change is sufficient, change element of A (2,1)=3 to B(2,1)=0, hence B is
B= [3,3,3,2,2,2; 0,2,3,3,1,2; 3,1,0,1,3,2]
base2base(‘333222’,4,10)
base2base(‘023312’,4,10)
base2base(‘310132’,4,10)
%ans = ‘4074’
%ans = ‘758’
%ans = ‘3358’
%Sum all in decimal to check if it is in base 4
S2=4074+758+3358
%S2 = 8190
% Which is the sought result. The program should be able to do such conversions of A to B for any input A I have a given Matrix A=k x n (k rows and n columns), with all elements digits in base 4,(can be only {0,1,2,3}). I want to write a program to change for any input matrix A to a new output B matrix respecting a condition. The condition is to change the least number of elements of A to form a modified matrix B(which keeps all the other unchanged elements of A), such that the k numbers of the row collated digits summed in base 4, are a multiple of (4^n)-1, expressed in base 4(n the number of columns of A and B)(The multiple must be the one such that B differs with the minimum nr of elements from A). Note that (4^n)-1 in base 4 is a row of n digits all 3s(3333…33, n times) . (4^3)-1 in base 4 = 333, However, a multiple of (4^3)-1, for instance [5*(4^3)-1] in base 4= 10323.
%I will give just an Example of a matrix A=3×6, k=3, n=6
A= [3,3,3,2,2,2; 3,2,3,3,1,2; 3,1,0,1,3,2]
%Convert row collated digits to numbers then to decimal
base2base(‘333222’,4,10)
base2base(‘323312’,4,10)
base2base(‘310132’,4,10)
%ans = ‘4074’
%ans = ‘3830’
%ans = ‘3358’
%Calculate their sum in base 10 of row digits 3 numbers
S=4074+3830+3358
%S = 11262
%Calculate (4^6) – 1 in decimal
(4^6) – 1
%4095
% One can see that a multiple of 2 of (4^6) – 1=8190, which can be expressed in base 4 , and is close to S
base2base(‘8190’,10,4)
%ans = ‘1333332’
%To get this row digits sum just one element change is sufficient, change element of A (2,1)=3 to B(2,1)=0, hence B is
B= [3,3,3,2,2,2; 0,2,3,3,1,2; 3,1,0,1,3,2]
base2base(‘333222’,4,10)
base2base(‘023312’,4,10)
base2base(‘310132’,4,10)
%ans = ‘4074’
%ans = ‘758’
%ans = ‘3358’
%Sum all in decimal to check if it is in base 4
S2=4074+758+3358
%S2 = 8190
% Which is the sought result. The program should be able to do such conversions of A to B for any input A min matrix elements change on condition MATLAB Answers — New Questions