how to enter exponential multiplication with a time dependent array

Given fa(t)=10*e^-5t and a time array of t=0:0.06:3 how do I enter this?
I have tried fa(t)=10*exp(-5*t) and I get an error message saying that the "Array indices must be positive intergers or logical values"

 採用された回答

Walter Roberson
Walter Roberson 2024 年 3 月 10 日
You need to decide whether you are doing array indexing, or are creating a formula.
t=0:0.06:3;
fa(t)=10*exp(-5*t)
is interpreted as array indexing. Using () indexing on the left hand side of an assignment is almost always interpreted as array indexing.
The formula form would be
t=0:0.06:3;
fa = @(t) 10*exp(-5*t);
plot(t, fa(t))
The major exception is if you are using a symbolic variable, then
syms t
fa(t)=10*exp(-5*t)
creates a formula, which you then apply like
T=0:0.06:3;
plot(T, fa(T))
But easiest is usually what Alexander shows,
t=0:0.06:3;
fa=10*exp(-5*t)
plot(t,fa)
which is pure expression form.

その他の回答 (1 件)

Alexander
Alexander 2024 年 3 月 10 日
編集済み: Alexander 2024 年 3 月 10 日

0 投票

Do you mean something like that:
t=0:0.06:3;
fa=10*exp(-5*t)
plot(t,fa)

カテゴリ

製品

リリース

R2023b

質問済み:

Jon
2024 年 3 月 10 日

回答済み:

2024 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by