Why won't this function plot?
2 ビュー (過去 30 日間)
古いコメントを表示
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
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
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)
回答 (2 件)
Simon Chan
2022 年 1 月 19 日
No need to use the for loop, Just use the following:
plot(c1_exp)
2 件のコメント
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))
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!