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 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