Why won't this function plot?

조회 수: 2 (최근 30일)
AUSTIN WHITELEY
AUSTIN WHITELEY 2022년 1월 19일
댓글: Steven Lord 2022년 1월 19일
For some reason I can't plot this function.
t=0:30;
c1_exp = b1*exp(-a1*t) + b2*exp(-a2*t);
All variables except for t are constants.
I've tried
fplot(c1_exp, 'g-', 'Linewidth', 3)
and
for ii= 1:30
plot(c1_exp(:,ii))
end
Nothing happens but I don't get any error messages.
What am I doing wrong?
  댓글 수: 1
Steven Lord
Steven Lord 2022년 1월 19일
What are the magnitudes (or the actual values) of your coefficients? If the value inside the exp calls gets too small, the exponential would underflow to 0.
exp(-750) % underflow
ans = 0
So if your a values were on the order of say 1000 only the points with t = 0 could possibly plot.
a = 1000;
t = 0:10;
y = exp(-a*t)
y = 1×11
1 0 0 0 0 0 0 0 0 0 0

댓글을 달려면 로그인하십시오.

답변 (2개)

Simon Chan
Simon Chan 2022년 1월 19일
No need to use the for loop, Just use the following:
plot(c1_exp)
  댓글 수: 2
AUSTIN WHITELEY
AUSTIN WHITELEY 2022년 1월 19일
that doesn't work
Voss
Voss 2022년 1월 19일
Are one or more of the constants NaN?

댓글을 달려면 로그인하십시오.


Voss
Voss 2022년 1월 19일
Try
plot(c1_exp)
or
plot(t,c1_exp)
With your for loop, you're plotting one data point at a time, which is impossible to see without a data marker. And fplot() is for plotting with a function handle, e.g.,
fplot(@(t) b1*exp(-a1*t) + b2*exp(-a2*t))

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by