Matrix n x n input

조회 수: 3 (최근 30일)
Rok
Rok 2011년 7월 21일
댓글: Rik 2021년 3월 9일
I'd like to know how can I input n x n matrix where n is not a specific number?
Thanks

답변 (6개)

Rok
Rok 2011년 7월 21일
I'd like to create a matrix size n x n in general. My problem is that I have to get determinant of a n x n matrix where n is unknown. My matrix looks something like: on the diagonal are {n, n-1, n-2,...,1} and some other elements which arent really important now.
I hope you understand what I mean.
In a sentence; do I have to state n = some_number,.... at the beginning or can I work with n as unknown at the moment.
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2011년 7월 21일
So you want an determinant as an analytical function of n? No, not clear yet.
Andrei Bobrov
Andrei Bobrov 2011년 7월 22일
mtx = diag(n:-1:1)

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


Sean de Wolski
Sean de Wolski 2011년 7월 21일
n = some_number;
matrix = rand(n)
matrix = magic(n)
matrix = zeros(n)
Please be more specific as to what you want.

Rick Rosson
Rick Rosson 2011년 7월 22일
You do not need to know the value of n at the beginning, but depending on what you want to do with your matrix, you may or may not need to know the value of n at some point later on.
For example, in the following code, the size of the variable x does not need to be known in advance, but it does need to be known at the time you choose to call this function:
function y = timestwo(x)
y = 2*x;
end
The only thing that is known in advance is that the size of y will be the same as the size of x, whatever that is at runtime. In addition, the data class and complexity of y will also be the same as x. But again, until you call this function, there is no way to know nor is there any need to know any of these characteristics of the variables x and y.
Can you please be more specific about what you would like to do, what you have tried so far, what is not working in what you have tried, and what you would like us to help you with?
Thanks!
Rick

Rick Rosson
Rick Rosson 2011년 7월 22일
By the way, you can always find out the value of n even if you do not know what it is in advance. You can also find out whether the matrix is square or not.
For example:
function y = dosomething(x)
[ m n ] = size(x);
if m == n
fprintf('The matrix is square \n');
else
fprintf('The matrix is NOT square \n');
end
...
end
  댓글 수: 2
Kristian Marc Lance Nery
Kristian Marc Lance Nery 2021년 3월 9일
Hi sir can you help me with this project :((
Rik
Rik 2021년 3월 9일
You already posted this as a separate question.

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


Neels
Neels 2011년 7월 22일
Are you trying to give a variable as an input, whose input is given dynamically during run time.

Rok
Rok 2011년 7월 22일
First I'd like to thank you.
Ok, here is my problem. I need to diagonalize a matrix size n x n. It's elements have variable n (size) in it.
It looks like this: [tex]\begin{bmatrix} tn&n-1&n-2&\cdots\\ n-1&t(n-1)&n-2&\cdots\\ n-2&n-2&t(n-2)&\cdots\\ \vdots&\vdots&& \end{bmatrix}[/tex]
And I need to find "t" so the determinant = 0.
ps: I hope this "tex code" helps.
  댓글 수: 2
Rick Rosson
Rick Rosson 2011년 7월 22일
The tex code does not help (at least not for me). Can you please convert the tex code to a PNG file, and then post it somewhere online where we can see it? Thanks.
Walter Roberson
Walter Roberson 2011년 7월 22일
I do not happen to "read TeX" either..

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by