why do i get this error? 'Subscript indices must either be real positive integers or logicals.' thanks for any help!!!
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
h=0.1;
t=36;
N=(t/h);
t=zeros(1,N+1);
p=zeros(1,N+1);
t(1)=0;
p(1)=87;
for n=1:N
t(n+1)=t(n)+h;
u=sin((2*pi*t)/12);
H=15*[nthroot(u,15)+1]
p1(n+1)=p(n)+h*[(0.016*p(n)*(100-p(n)))-H(n)];
p(n+1)=p(n)+(h/2)*[[(0.016*p(n)*(100-p(n)))-H(t)]+[(0.016*p(n+1)*(100-p(n+1)))-H(n+1)]];
end
Antworten (2)
Walter Roberson
am 3 Nov. 2015
Bearbeitet: Walter Roberson
am 3 Nov. 2015
Your line
p(n+1)=p(n)+(h/2)*[[(0.016*p(n)*(100-p(n)))-H(t)]+[(0.016*p(n+1)*(100-p(n+1)))-H(n+1)]];
includes the subexpression H(t). H(t) denotes indexing the vector H at the locations designated in t. But t is, at that point, a vector of values that are not integers, so this is going to fail.
In the other places you use H, you use H(n) or H(n+1) which do not have that problem.
Note: in MATLAB, [] designate building matrices or vectors, rather than being parenthesis. There are a number of cases where you would get away with using [] instead of () but it will cause problems eventually.
Stalin Samuel
am 3 Nov. 2015
0 Stimmen
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!