Create a n*n matrix

Create a n*n matrix A such that A_(n, n-1) = n and A_(n, n) = -(n-1)

4 件のコメント

Dyuman Joshi
Dyuman Joshi 2023 年 2 月 25 日
What about the rest of the elements? What value should they have?
Steven Lord
Steven Lord 2023 年 2 月 25 日
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Nischal
Nischal 2023 年 3 月 1 日
It is not a homework problem. I needed to create a n*n matrix to verify some of my results. Other elements have variables in diagonal and sub diagonal.
Dyuman Joshi
Dyuman Joshi 2023 年 3 月 3 日
"Other elements have variables in diagonal and sub diagonal."
Which variables? Please give an example.
Let's say n = 5, what should be the output?

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2023 年 2 月 25 日

0 投票

This looks like a homework problem. If you have any questions ask your instructor or read the link below to get started:
Obviously we can't give you the full solution because you're not allowed to turn in our code as your own. Hint: use zeros followed by a single for loop.
To learn other fundamental concepts, invest 2 hours of your time here:
Image Analyst
Image Analyst 2023 年 3 月 2 日
編集済み: Image Analyst 2023 年 3 月 2 日

0 投票

OK, please tell me you did not ignore my last answer and that you actually did spend the two hours to do the basic training. If you did, you would easily have been able to write this loop:
% Require A_(n, n-1) = n and A_(n, n) = -(n-1)
n = 5;
A = zeros(n, n);
for k = 1 : n
A(k, k) = -(k+1);
end
for k = 2 : n
A(k, k-1) = k;
end
A % Display in command window.
A = 5×5
-2 0 0 0 0 2 -3 0 0 0 0 3 -4 0 0 0 0 4 -5 0 0 0 0 5 -6
Does that look like what you did? Actually I'm guessing you ignored my answer and didn't take the training or else you wouldn't have to ask again several days later. Anyway, you can use this code. I hope it helps.

カテゴリ

製品

リリース

R2022b

質問済み:

2023 年 2 月 25 日

コメント済み:

2023 年 3 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by