Can you help me draw the plot with decimals?

2 次查看(过去 30 天)
clear;
clc;
k=0.7944;
firstone=2;
carry=64;
syms f(y)
syms y
f(y)=k*y*(carry-y)
f(y) = 
endday=0.1;
dt=0.01;
n=endday/dt;
i=1;
for i=1:n
xia=i*dt;
yi=f(xia);
I1(i/n)=(1/(1-yi*dt))^(i)*firstone;
end
Array indices must be positive integers or logical values.

Error in sym/privsubsasgn (line 1307)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);

Error in indexing (line 1138)
C = privsubsasgn(L,R,inds{:});
dt=0.001;
k=endday/dt;
i=1;
for i=1:k
xib=i*dt;
yi=f(xib);
I2(i/k)=(1/(1-yi*dt))^(i)*firstone;
end
figure(1)
plot(I1)
figure(2)
plot(I2)
Arrays must be indexed by int values. But I have to draw the plot with decimals. Please help.
  1 个评论
Jan
Jan 2022-5-28
编辑:Jan 2022-5-28
What exactly is your question? What does this mean: "Arrays must be indexed by int values."? Is this a paraphrased error message? If so, please post a copy of the message instead.
I've edited your question and pressed the Run button, such that the error message is displayed.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2022-5-28
I1(i/n) = ...
This cannot work. i/n is not an integer and therefore not possible as index. Remember what indices are: X(k) addresses the k.th element of the vector X. So what should I1(i/n) be?
The solution is easy: Use I1(i) instead. If you need to define the X values with a fractional part in the plot, define the X values of the plot accordingly:
% plot(I1) ==>
plot((1:n) / n, I1)
Note:
i=1; % <== Useless, because i is overwritten in the next line:
for i=1:n

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by