Info
此问题已关闭。 请重新打开它进行编辑或回答。
why do i get this error? 'Subscript indices must either be real positive integers or logicals.' thanks for any help!!!
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Walter Roberson
2015-11-3
编辑:Walter Roberson
2015-11-3
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.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!