Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Index exceeds the number of elements (1) HELP
조회 수: 7 (최근 30일)
이전 댓글 표시
it gives me an error with the x1 calculation
% Ask for inputs
y1 = input('Please input y1:');
t = input('Please input T:');
% Calculations
y2 = 1-y1;
p1 = exp(16.59158-(3643.31/(t-33.424)));
p2 = exp(14.25326-(2665.54/(t-53.424)));
a = 2.771-(0.00523*t);
% Initialize
c1(1) = 1;
c2(1) = 1;
% Initial P calculation
p(1) = 1./((y1/(c1(1)*p1)+(y2/(c2(1)*p2))));
% loop
for i = 2:8
% update calculations
x1(i) = (y1.*p(i-1))./(c1(i).*p1);
x2(i) = (y2.*p(i-1))./(c2(i).*p2);
c2(i) = exp(a.*(x1(i).^2));
c1(i) = exp(a.*(x2(i).^2));
p(i)= 1./((y1./(c1(i).*p1)+(y2./(c2(i).*p2))));
end
댓글 수: 1
tejas alva
2019년 3월 24일
x1(i) = (y1.*p(i-1))./(c1(i).*p1);
c1(i) in the for loop would start with c1(2) which has not been initialized. I think if you sort that for all variables, including c2, it should not throw you any error.
답변 (1개)
Anant Upadhyay
2019년 3월 27일
Hi Cansu,
According to my understanding, you are facing error while calculating x1 because, in the expression
>> x1(i) = (y1.*p(i-1))./(c1(i).*p1);
“x1(i)” depends upon the value of “c1(i)” which is not being initialized/pre-calculated. Similar pattern is repeated for “x2(i)” also.
It may be a case, that for updating “x1(i)” you require “c(i-1)” and not “c(i)”.
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!