Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

need help with a for loop

조회 수: 1 (최근 30일)
Daniel Council
Daniel Council 2016년 6월 7일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi All, I am trying to get this for loop to execute, and I'm not sure what I am doing wrong here. I was wondering if you could help me out. It keeps telling me that my matrix dimensions must agree, but I'm pretty sure that they do.
%Define Variables
A=[100,0,.1;.01,50,0;0,.01,200];
b=[1;1;1];
x=A\b;
r=b-A*x;
c=A\r;
%My for loop
a=1:3;
for a=1:length(a)
r(a)= b+(A*x(a))
c(a)=A\r(a)
x_new=x(a)+c(a)
end
any help you could give me would be really appreciated
  댓글 수: 1
per isakson
per isakson 2016년 6월 7일
편집: per isakson 2016년 6월 7일
"pretty sure that they do" &nbsp Check b+(A*x(a)) once more
Replace the name of the counter a by e.g. jj

답변 (1개)

freebil
freebil 2016년 6월 7일
In the second line of the for loop, b is 3x1 and (A*x(a)) is 3x3. So, you cant sum these. For summing, they must have identical dimensions.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by