How to write code for diagonal matrix with specified input ?
显示 更早的评论
For n*n diagonal matrix :
n = input (' enter the order of the matrix : ');
s = input (' enter the value of s : ');
My question is if m = 3 and s = 1 then I should get my matrix as [a11] = 1 and remaining entries 0
if m = 3 and s = 2 then [a11] = 1 , [a22] = 1 and remaining entries o.
please help me out with this :)
2 个评论
Walter Roberson
2022-5-27
We recommend that you do not dynamically create variable names such as a93829382.
Walter Roberson
2022-5-27
a(i, i) = 1
采纳的回答
更多回答(1 个)
kainat rasheed
2022-5-27
v = [1 2 3 4 5];
use this matrix to use specific numbers like this
after that write it as
D = diag(v)
v = [1 2 3 4 5];
D = diag(v)
run the code
类别
在 帮助中心 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!