Question on function handles

Hi
I am looking at the code for "Learning the Extended Kalman Filter" by by Yi Cao on the File Exchange. In the code , there are a couple of lines that I couldnt get:
f=@(x)[x(2);x(3);0.05*x(1)*(x(2)+x(3))]; h=@(x)x(1);
Can someone explain how handles work here? (in terms of plain math)

댓글 수: 1

per isakson
per isakson 2012년 6월 20일
Did you read on "function handle" in the online documentation?

댓글을 달려면 로그인하십시오.

 채택된 답변

Tom
Tom 2012년 6월 20일

1 개 추천

Roughly speaking, f and h are handles to small functions- functions that have been made without having to actually write
function [Out1 Out2...] = FunctionName(In1,In2...)
function handles allow you to run a function using a variable name instead of having to write the name of the function.
For a simpler example:
F=@(x) x(x>5);
F is the function handle, and x(x>5) is the code that it executes if you enter
y=F(1:10)
you will see that it returns the numbers greater than 5.

댓글 수: 3

Walter Roberson
Walter Roberson 2012년 6월 20일
The above is correct, but it does not happen to be the mathematical description ;-)
Tom
Tom 2012년 6월 20일
Are you suggesting that counting to ten is in some way less rigorous than domains and tuples?
Walter Roberson
Walter Roberson 2012년 6월 20일
It is the "code that it executes" part that is the less rigorous. That and the "run a function". What it *means* to "run a function", in rigorous terms, is surprisingly complex. And what the colon operator does, precisely, when the the increment includes a non-zero fractional part, is a headache.
Did you remember to specify that you are expecting this to be executed on a machine with at least 4 bits? (or 3 bits if using trinary, or 2 bits if using quaternary, .... ) ? :-)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 6월 20일

0 개 추천

In terms of plain math:
A function handle is a projection of a subspace of a domain (represented by a tuple) on to a subspace of a range (represented by a tuple). The projection function is arrived at by currying the original function to creating a new function which embeds all elements of the tuple that are to be treated as constants with respect to the projection.
If you prefer, I could rephrase in terms of Denotational Semantics, but I think I packed my reference book for that.
I think you will find the use of function handles rather clearer if you think of them procedurally rather than mathematically, and examine the online MATLAB documentation on function handles.

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

질문:

2012년 6월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by