0

I want to create a multi-plot from each array of matrix y:

q = [...] % (a 1x6 matrix)
p = [...] % (a 6x6 matrix)
x = [0:1:40];
y = q * p ^ x;

But I get this error:

Error using  ^ 
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
1

3 Answers 3

1

To avoid blow-ups in power computations, do not compute the powers explicitly but instead use intermediate results

y = zeros(41,6);
y(1,:) = q;
for ind = 1:40
    y(ind+1,:) = y(ind,:)*p;
end
Sign up to request clarification or add additional context in comments.

Comments

0
q = [...] ( a 1x6 matrix)
p = [...] ( a 6x6 matrix)
x = [0:1:40];
y = [] ;
for i = 1 : length (x)
    y(i,:,:) = q * p .^ x(i);
end

q * p will generate the matrix of size of 6 x 6. y will be 3 dimensional matrix of size of 41 x 6 x 6.

Comments

0

try to fix this line as

for k=1:40
y = q * p ^ k;
end

also you can do this as

for k=1:40
y = q * p ^ x(k);
end

also it will takess power of p as x then multiple q * p ^ x;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.