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)
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
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
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 Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!