Can you help me draw the plot with decimals?

2 views (last 30 days)
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 Comment
Jan
Jan on 28 May 2022
Edited: Jan on 28 May 2022
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.

Sign in to comment.

Accepted Answer

Jan
Jan on 28 May 2022
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!