필터 지우기
필터 지우기

another basic question for a beginner

조회 수: 2 (최근 30일)
Eliraz Nahum
Eliraz Nahum 2018년 9월 21일
답변: Star Strider 2018년 9월 21일
I saw the 2 forms of writing:
  • fzero(f,x0)
  • fsolve(@(x)f,xo)
in both cases we use symbolic function (f) before the above orders.
I am trying to understand why in the first case we could write only "f", while in the second one we had to write the whole expression "@(x)f"?

채택된 답변

Star Strider
Star Strider 2018년 9월 21일
Without knowing the relevant context, it is difficult to say.
The first syntax:
fzero(f,x0)
implies that ‘f’ is a function of one variable, and already exists in the workspace as a function handle.
The second syntax:
fsolve(@(x)f,x0)
actually throws this error when I run it (in R2018b):
Error using fsolve (line 281)
FSOLVE requires all values returned by functions to be of data type double.
The correct way to use that syntax is to express ‘f’ as a function to be evaluated:
fsolve(@(x)f(x),x0)
and this works correctly.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by