How to create a Aij matrix with the commands 'for', 'function output=name_of_code' and 'imagesc'?

1 回表示 (過去 30 日間)
I have to built a Aij matrix where Aij=i^2+j^2 when i=j and Aij=(i-j)^2 when i≠j. After that, I need to execute the code with m=100 and n=150. My teacher said the useful commands are 'for', 'function output=name_of_code' and 'imagesc'. I don't know how to do it and I didn't find any example. I write the code: for A=i^2+j^2
i=j
end
for A=(i-j)^2
i~=j
end
This appear on the command window: i =
0.0000 + 1.0000i
ans =
0
I don't know if what I've done is good. After I write m=[1:100]
n=[1:150]
A=[m,n]
imagesc(A)
function [A]=matrice_A
end
for A=i^2+j^2
i=j
end
It gives me this figure. I don't know if it is good but it doesn't look like a matrix.
  2 件のコメント
Matt J
Matt J 2023 年 1 月 27 日
移動済み: Matt J 2023 年 1 月 27 日
I don't know how to do it and I didn't find any example.
Not even here?
Matt J
Matt J 2023 年 1 月 27 日
編集済み: Matt J 2023 年 1 月 27 日
Ariane wrote:
I have to built a Aij matrix where Aij=i^2+j^2 when i=j and Aij=(i-j)^2 when i≠j. After that, I need to execute the code with m=100 and n=150. My teacher said the useful commands are 'for', 'function output=name_of_code' and 'imagesc'. I don't know how to do it and I didn't find any example. I write the code: for A=i^2+j^2
i=j
end
for A=(i-j)^2
i~=j
end
This appear on the command window: i =
0.0000 + 1.0000i
ans =
logical
0
I don't know if what I've done is good. After I write m=[1:100]
n=[1:150]
A=[m,n]
imagesc(A)
function [A]=matrice_A
end
for A=i^2+j^2
i=j
end
It gives me this figure. I don't know if it is good but it doesn't look like a matrix.

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

採用された回答

Matt J
Matt J 2023 年 1 月 27 日
m=100; n=150;
A=((1:m)'-(1:n)).^2;
for i=1:min(m,n)
A(i,i)=2*i.^2;
end
imagesc(A)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDynamic System Models についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by