Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Index exceeds the number of elements (1) HELP

2 visualizzazioni (ultimi 30 giorni)
Cansu Karaca
Cansu Karaca il 24 Mar 2019
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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 Commento
tejas alva
tejas alva il 24 Mar 2019
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.

Risposte (1)

Anant Upadhyay
Anant Upadhyay il 27 Mar 2019
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)”.

Questa domanda è chiusa.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by