how do I evaluate the value of an expression?

10 次查看(过去 30 天)
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.

更多回答(1 个)

Joshua Hodson
Joshua Hodson 2021-2-10
6x4>32-3

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by