How to make a symmetric matrix

54 次查看(过去 30 天)
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 个评论
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
... 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 个评论
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
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 个评论
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by