Unable to plot matrix multiples
2 次查看(过去 30 天)
显示 更早的评论
So I'm trying to plot the sum of a matrix at 25 different values using the code below, but matlab gives me the error " Error using ^ One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power. ", Even though x technically is a scalar (right?). Note that i am NOT trying to simply multiply the matrix by a constant x. For x=2 I want to compute A*A (matrix multiplication).
clear all
A = [1.9 0.025;0.1 1.225];
v = [1;0];
for i = 1:25 answer = sum((A^i)*v); end
answer
x = (1:25);
y = sum((A^x)*v);
plot (x,y)
xlabel('# of growth periods')
ylabel('Total # of bacteria')
0 个评论
采纳的回答
Birdman
2018-2-9
编辑:Birdman
2018-2-9
A = [1.9 0.025;0.1 1.225];
v = [1;0];
for i = 1:25
answer(i) = sum((A^i)*v);
end
x = 1:25;
plot (x,answer)
xlabel('# of growth periods')
ylabel('Total # of bacteria')
2 个评论
Birdman
2018-2-9
pvalues = 0:0.01:1;
v = [1;0];
for i=1:length(pvalues)
A = [2-pvalues(i) 0.25*pvalues(i);pvalues(i) (1.25-(0.25*pvalues(i)))];
res = (A^25)*v;
val(i)=max(res);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!