create a matrix from a matrix x=[-2 -1 0 1 2]; which follow quadratic equations

1 Ansicht (letzte 30 Tage)
Hi everyone, i want to create a matrix from this matrix x=[-2 -1 0 1 2] in such a way that resultant matrix is [ (-2^2),(-2^1),(-2^0); (-1^2),(-1^1),(-1^0); (0^2),(0^1),(0^0); (1^2),(1^1),(1^0); (2^2),2^1),(2^0) ]

Akzeptierte Antwort

Alexandra Harkai
Alexandra Harkai am 30 Nov. 2016
x = [-2:2];
y = [2:-1:0];
bsxfun(@power, x', y)
  3 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 30 Nov. 2016
Bearbeitet: Andrei Bobrov am 30 Nov. 2016
x = [-2 -1 0 1 2];
out = x(:).^(2:-1:0); % for R2016b

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by