フィルターのクリア

how do I evaluate the value of an expression?

10 ビュー (過去 30 日間)
Matteo Masto
Matteo Masto 2019 年 11 月 2 日
回答済み: Joshua Hodson 2021 年 2 月 10 日
x = [-2:0.01:1];
f = (x.^2) -x +1 - (exp(-x));
x1 = -1.9;
f(x1)
this gives me the error:
Array indices must be positive integers or logical values
How can I manage to extract the right value of f at x1?
thanks!

採用された回答

Star Strider
Star Strider 2019 年 11 月 2 日
Try this:
f = @(x) (x.^2) -x +1 - (exp(-x));
x1 = -1.9;
fx1 = f(x1)
creating an anonymous function and producing:
fx1 =
-0.175894442279269
See the documentation section on Anonymous Functions for details.
  2 件のコメント
Matteo Masto
Matteo Masto 2019 年 11 月 5 日
thank you very much!!
Star Strider
Star Strider 2019 年 11 月 5 日
As always, my pleasure!

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

その他の回答 (1 件)

Joshua Hodson
Joshua Hodson 2021 年 2 月 10 日
6x4>32-3

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by