Error using / Arguments must be numeric, char, or logical.

18 ビュー (過去 30 日間)
Antônio Carvalho
Antônio Carvalho 2022 年 5 月 22 日
回答済み: Image Analyst 2022 年 5 月 22 日
When i input this code :
t=0:1:10;
y=2.718.^(-t/5)-{[2.718.^(-t/5)].*t}/5;
plot(t,y(t))
the program reclaims : Error using /
Arguments must be numeric, char, or logical.
How can i solve this please ?

回答 (2 件)

VBBV
VBBV 2022 年 5 月 22 日
編集済み: VBBV 2022 年 5 月 22 日
y=@(t) 2.718.^(-t/5)-(2.718.^(-t/5).*t)/5;
t=0:1:10;
plot(t,y(t))
Define the equation as anonymous function and plot

Image Analyst
Image Analyst 2022 年 5 月 22 日
You can get rid of the (t) in plot. Also get rid of the braces in the definition of y because that puts what's inside of the braces into a cell and you can't subtract a cell from a number. See the FAQ:
You can also use exp instead of raising 2.718 to a power. Fixed code:
t = 0 : 10;
y = exp(-t/5) - exp(-t/5) .* t / 5;
plot(t, y, 'b-');
grid on;
xlabel('t');
ylabel('y');

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by