Can you help me draw the plot with decimals?
2 views (last 30 days)
Show older comments
clear;
clc;
k=0.7944;
firstone=2;
carry=64;
syms f(y)
syms y
f(y)=k*y*(carry-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
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
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.
Accepted Answer
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)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!