(a) Write a MATLAB function matrixfn that takes values m and n as inputs and gives as output an m × n matrix A whose entries Aij are defined by Aij = i^2 + j^2
(b) Write MATLAB commands that use matrixfn to obtain the m × n matrix A for the following cases: (i) m = n = 5. (ii) m = 6, n = 9
THIS IS WHAT I HAVE DONE:
function A= matrixfn(m,n)
for i=1:n
for j=1:m
A(i,j)=i^2 + j^2;
end
end

2 件のコメント

Walter Roberson
Walter Roberson 2018 年 11 月 12 日
Your output would be n x m instead of m x n
Tawanda Le Bourne
Tawanda Le Bourne 2018 年 11 月 12 日
so it's i=1:m j=1:n

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

 採用された回答

KSSV
KSSV 2018 年 11 月 12 日
編集済み: KSSV 2018 年 11 月 12 日

0 投票

function A= matrixfn(m,n)
A = zeros(m,n) ;
for i=1:m
for j=1:n
A(i,j)=i^2 + j^2;
end
end
Save the above function in a folder. Go to that folder in MATLAB. And you can call it by:
A = matrixfun(2,2) ;
B = matrixfun(5,5) ;
C = matrixfun(6,9) ;

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2018 年 11 月 12 日

編集済み:

2018 年 11 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by