Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentarios
Matt J
Matt J el 27 de En. de 2023
Editada: Matt J el 27 de En. de 2023
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.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 27 de En. de 2023
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)

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by