hey,
the assiment is a challange
-to create this matrix in one row of code by using Matlab methods ( also multiplying metrix and Vectors are permited ).
i cant write the matrix directly(also simple operations
example:
[1;1;1]+[2;2;2] to get [3;3;3].)
my wish to get the specific matrix:
B = [1 2 3 8 1 6 ; 2 1 0 3 5 7; 3 0 1 4 9 2; 8 3 4 1 0 3 ; 1 5 9 0 1 2; 6 7 2 3 2 1]
my intuition is to found some legality or somthing like that, and to use it to get a simple solution(1 row with the shortest way.).
B =
1 2 3 8 1 6
2 1 0 3 5 7
3 0 1 4 9 2
8 3 4 1 0 3
1 5 9 0 1 2
6 7 2 3 2 1

댓글 수: 10

nanren888
nanren888 2019년 1월 7일
Sorry, don't get what you want.
You have it in a one-line command now.
Do you want B(:).'?
(one row?)
newCoder
newCoder 2019년 1월 8일
hey i like to get B in 1 row, but not to write the matrix directly.
my meaning that i have to use in one or couple commands to get this matrix except adding matrix, multiply matrix.
but i can adding matrix who came from command and not defined like that [1 2 3;4 5 6;7 8 9]
Walter Roberson
Walter Roberson 2019년 1월 8일
part of what you write seems to suggest that matrix addition is not permitted but then you seem to say that it is permitted ??
Jan
Jan 2019년 1월 8일
B is a matrix. So what exactly is "get B in 1 row"? Why "except adding matrix, multiply matrix"? Which problem do you want to solve? What is "coming from command"?
newCoder
newCoder 2019년 1월 8일
the assiment is to create this matrix in one row of code by using Matlab methods ( also multiplying metrix and Vectors are permited ).
i cant write the matrix directly.
Image Analyst
Image Analyst 2019년 1월 9일
Is it still a challenge for you if we do it for you? If a challenge was presented to me, and I just asked an expert to do it for me, I don't think I'd be very satisfied with my capabilities, and (personally) might even feel guilty or incapable.
John D'Errico
John D'Errico 2019년 1월 10일
편집: John D'Errico 2019년 1월 10일
Why does this feel like a homework assignment, almost certainly for extra credit in some form? If so, then if we answer and you turn it in, that is equivalent to cheating. Surely you would not ask us to help you do that? In that case, this question should arguably have been closed from the beginning.
If it is not for homework, and just some random challenge for some reason that you want to solve, then you will gain far more by spending the time to figure it out, rather than being told the answer. That does nothing for you. So again, there is no incentive for us to help you on it.
newCoder
newCoder 2019년 1월 10일
thanks for your opinion , i am appreciate your intentions!.
its a part of 'riddle' that given on my course, not belong to homework, the main idiea its to explore what is 'magic square' . already solved.
John D'Errico
John D'Errico 2019년 1월 10일
편집: John D'Errico 2019년 1월 10일
If it is for your course, credit or not, it is inappropriate to ask for someone else to do your work. I'll ask that you not do it again, as this question is inappropriate for Answers.
Walter Roberson
Walter Roberson 2019년 12월 11일
Ryan Dreifuerst comments to John D'Errico
It is not very helpful to provide feedback of the form "it is inappropriate to ask someone else to do your work" when you do not understand the problem. The entire point of many assignments or challenges is to see an interesting concept or result which may be entirely unrelated to the question but assumed that had been done in prior work. It is unreasonable to expect every person to rederive or resolve every problem, so providing helpful feedback, even without code, would at least provide some idea. Seems like that MVP tag is not earned from being particularly helpful... Note that I am in no way related to this, just read it as I was considering a similar concept and was astounded at how inappropriate this answer was by scolding the asker for being inappropriate.

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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 1월 8일
편집: Andrei Bobrov 2019년 1월 8일

4 개 추천

... make a symmetric matrix:
M = tril(randi([0 9],6),-1);
B = M + M' + eye(6);
Maybe use function toeplitz:
B = toeplitz(randi([0 9],6,1));

댓글 수: 5

newCoder
newCoder 2019년 1월 9일
편집: newCoder 2019년 1월 9일
thanks for trying i need the specific matrix (B)
B = [1 2 3 8 1 6 ; 2 1 0 3 5 7; 3 0 1 4 9 2; 8 3 4 1 0 3 ; 1 5 9 0 1 2; 6 7 2 3 2 1]
Andrei Bobrov
Andrei Bobrov 2019년 1월 10일
편집: Andrei Bobrov 2019년 1월 10일
n = 3;
M = toeplitz(1:n).*~flip(diag(ones(n-1,1),-1),2);
N = magic(n);
B = [M,N;N',rot90(M,2)]
newCoder
newCoder 2019년 1월 10일
aswome! magic square its the missing part, thanks! .
Prima Aditya
Prima Aditya 2021년 4월 25일
does topelitz matrix always symmetric?
Walter Roberson
Walter Roberson 2021년 4월 25일
No. See the first example at https://en.wikipedia.org/wiki/Toeplitz_matrix and see that it is not typically symmetric.

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

추가 답변 (1개)

Jan
Jan 2019년 1월 7일
편집: Jan 2019년 1월 7일

1 개 추천

What about using the code you have posted already?
B = [1 2 3 8 1 6 ; 2 1 0 3 5 7; 3 0 1 4 9 2; 8 3 4 1 0 3 ; 1 5 9 0 1 2; 6 7 2 3 2 1]
What is a "one row command"?
Maybe:
B = reshape([1 2 3 8 1 6 2 1 0 3 5 7 3 0 1 4 9 2 ...
8 3 4 1 0 3 1 5 9 0 1 2 6 7 2 3 2 1], 6, 6)
Or maybe it should be a random matrix:
x = randi([0,4], 1, 6);
B = x + x.'

댓글 수: 3

newCoder
newCoder 2019년 1월 8일
Hey thanks for the trying, i want to be more specific:
i like to get B in 1 row, but not to write the matrix directly.
my meaning that i have to use in one or couple commands to get this matrix except adding matrix, multiply matrix.
but i can adding matrix who came from command and not defined like that [1 2 3;4 5 6;7 8 9]
Jan
Jan 2019년 1월 8일
I do not understand, what you are asking for.
newCoder
newCoder 2019년 1월 9일
the assiment is a challange.
-to create this matrix in one row of code by using Matlab methods ( also multiplying metrix and Vectors are permited ).
i cant write the matrix directly(also simple operations
example:
[1;1;1]+[2;2;2] to get [3;3;3].)
my intuition is to found some legality or somthing like that, and to use it to get a simple solution.

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

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

2019년 1월 7일

댓글:

2021년 4월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by