errors on function vs time plot

3 ビュー (過去 30 日間)
Laila
Laila 2023 年 1 月 19 日
コメント済み: Star Strider 2023 年 1 月 19 日
Hi, I am trying to make a function vs time plot of v = 12e^(-8t) vs time using t =linspace(-1,1,100) (i also wasnt sure what parameters to use for the linspace funcation) where v = 0 when t is less then 00. But when i try to run the code it says there is an error in my v(t) equation line. I have't used MATHLAB a lot so im not sure if its a sytax issue or something else. This is my code. Thanks for any help!
system v(t)
t = linspace(-1,1,100);
v(t) = 12.*e^-8.*t;
if t < 0
v(t) = 0;
plot(v(t), t);
end
  1 件のコメント
Laila
Laila 2023 年 1 月 19 日
I have also tried using exp(1) instead of e but still no luck.

サインインしてコメントする。

回答 (2 件)

Torsten
Torsten 2023 年 1 月 19 日
編集済み: Torsten 2023 年 1 月 19 日
t = linspace(-1,1,100);
v = 12*exp(-8*t).*(t>=0);
plot(t,v)
  1 件のコメント
Laila
Laila 2023 年 1 月 19 日
thank you!

サインインしてコメントする。


Star Strider
Star Strider 2023 年 1 月 19 日
The exponential function in MATLAB (and every other programming language I have encountered) is exp.
Try something like this —
t = linspace(-1,1,100);
v = @(t) 12.*exp(-8.*t);
vt = v(t);
vt(t < 0) = 0;
figure
plot(t, vt);
.
  2 件のコメント
Laila
Laila 2023 年 1 月 19 日
thank you!
Star Strider
Star Strider 2023 年 1 月 19 日
My pleasure!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by