Info
此问题已关闭。 请重新打开它进行编辑或回答。
Index exceeds the number of elements (1) HELP
1 次查看(过去 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!