Matrix problem with pattern in rows and columns

조회 수: 10 (최근 30일)
Daabir Momin
Daabir Momin 2022년 2월 16일
답변: Benjamin Thompson 2022년 2월 16일
So I want a matrix that looks like this:
[a^1, (a+1)^2, (a+2)^3....;(a+2)^1, (a+3)^2,(a+4)^3....;(a+4)^1, (a+5)^2,(a+6)^3....;(a+6)^1, (a+7)^2,(a+8)^3...]
all the way to the power of 15 for each row (15 rows) and 5 columns with this pattern. Also, I cannot type out the exact numbers explicitly. I tried looking for resources but wasn't able to find something to help me with this. Help would be really appreciated thank you in advance.

답변 (1개)

Benjamin Thompson
Benjamin Thompson 2022년 2월 16일
The brute force way is:
a = 2;
M = zeros(15,5);
M(1, 1) = a;
M(1, 2) = (a+1)^2;
M(1,3) = and so on...
M(2, 1) = (a+2)^3;
and so on...
You can also square just the second column of a matrix if you wish using this command:
M(:,2) = M(:,2).^2
And if you construct a 15x5 matrix with the integers you would like to add to a:
N = 1:(15*5);
N = reshape(N,15,5)
Then you can add a to all elements of that matrix like this:
M = ones(15,5)*a + N
I cannot fully understand pattern of the contents of the 15x5 matrix to complete all of it. Hopefully these examples are helpful.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by