Borrar filtros
Borrar filtros

In the following in program, I want print only the resultant Matrix D which its sum is zero also their corresponding combinations Matrix E a using any conditional statements

1 visualización (últimos 30 días)
A = [0 1 0 0 0 1 ; 1 0 1 0 0 0 ; 0 1 0 1 0 0 ; 0 0 1 0 1 0; 0 0 0 1 0 1 ; 1 0 0 0 1 0];
B = [1; 2; 3; -3; -2; -1];
C = perms (B);
E=C
D=C*A
output:
E = 3 2 1 -1 -2 -3
3 2 1 -1 -3 -2
3 2 1 -2 -1 -3
3 2 1 -2 -3 -1
3 2 1 -3 -1 -2
3 2 1 -3 -2 -1 and so on...
D = -1 4 1 -1 -4 1
0 4 1 -2 -3 0
-1 4 0 0 -5 2
1 4 0 -2 -3 0
0 4 -1 0 -5 2 and so on...
Here i have lot of outputs for E and D.
so, I want print only the resultant Matrix D with two conditions
i) Matrix D has atmost one zero.
ii) Sum of all elements in D = 0.
and also their corresponding combination of Matrix E
by using any conditional statements (example for , if conditions).
  • if exist such matrix D & E, then display "Matrix D and corresponding Matrix E"
  • if does not exist such Matrix, then display " there is no such combination".

Respuestas (1)

Enrico Gambini
Enrico Gambini el 1 de Mzo. de 2022
Editada: Enrico Gambini el 1 de Mzo. de 2022
If I got it right...
if ((sum(any(D,'all'))<=1) & (sum(D,'all'))==0 &(sum(any(E,'all'))<=1) & (sum(E,'all'))==0)
fprintf("Matrix D and corresponding Matrix E\n");
else
fprintf("There is no such combination \n");
end
  1 comentario
bala maths
bala maths el 1 de Mzo. de 2022
i have this error
error: any: DIM must be an integer
error: called from
jdoodle at line 7 column 1
Can you execute this program?

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by