Filter löschen
Filter löschen

how do I evaluate the value of an expression?

10 Ansichten (letzte 30 Tage)
Matteo Masto
Matteo Masto am 2 Nov. 2019
Beantwortet: Joshua Hodson am 10 Feb. 2021
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!

Akzeptierte Antwort

Star Strider
Star Strider am 2 Nov. 2019
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 Kommentare
Matteo Masto
Matteo Masto am 5 Nov. 2019
thank you very much!!
Star Strider
Star Strider am 5 Nov. 2019
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Joshua Hodson
Joshua Hodson am 10 Feb. 2021
6x4>32-3

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by