"Subscriped assignment dimension missmatch" Error
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
BhaTTa
am 21 Okt. 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.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!