Can you help me draw the plot with decimals?

조회 수: 2 (최근 30일)
seoung gi Sin
seoung gi Sin 2022년 5월 28일
댓글: seoung gi Sin 2022년 5월 31일
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