"Subscriped assignment dimension missmatch" Error

14 visualizaciones (últimos 30 días)
Lukas Lehrman
Lukas Lehrman el 9 de Feb. de 2018
Respondida: BhaTTa el 21 de Oct. de 2024
So I'm trying to calculate the value of an unknown that would generate the maximum value in a matrix, but I've ran into a problem. I get the error "Subscripted assignment dimension mismatch". So to clarify, I'm looking for the p that, after the operation below is performed, Generates the highest number. I then need to find that p.
pvalues = [0:0.01:1];
v = [1;0];
for i=1:length(pvalues)
p=pvalues(i)
A = [2-p 0.25*p;p (1.25-(0.25*p))];
answer(i) = (A^25)*v;
end
max(answer)
I thought i could work around it, but it seems that it hasn't worked.

Respuestas (1)

BhaTTa
BhaTTa el 21 de Oct. de 2024
Hey @Lukas Lehrman, hey there is a minor mistake in your code as 'A' is 2x2 matrix and 'v' is 2x1 matrix and the resultant matrix obtained after their multiplication is 2x1 matrix, thereby you should assign the value to answer by doing answer(i,:).
pvalues = [0:0.01:1];
v = [1;0];
for i=1:length(pvalues)
p=pvalues(i)
A = [2-p 0.25*p;p (1.25-(0.25*p))];
answer(i,:) = (A^25)*v;
end
max(answer)
hope it resolved your issue.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by