@(x) and inline

Hello
Anyone who knows the main difference between the two arguments “@(x)” and “inline” as in:
incsearch(@(x) sin(10*x) + cos(3*x),3,6)
incsearch(inline('sin(10*x)+cos(3*x)'),3,6)
And when to use which? Or are they simply equal?
Thanks.
/R

Respuestas (2)

the cyclist
the cyclist el 30 de Ag. de 2013

1 voto

I haven't used inline() in such a long time, that I can't remember if there are any differences.
However, you should definitely use @(x), aka "anonymous functions", from now on, because inline() is slated to be removed in a future a release.
Azzi Abdelmalek
Azzi Abdelmalek el 30 de Ag. de 2013

0 votos

f1=@(x) sin(10*x) + cos(3*x)
f2=inline('sin(10*x)+cos(3*x)')
f1(10)
f2(10)
inline and @(function_handle) do the same thing, inline is older then @.

3 comentarios

Walter Roberson
Walter Roberson el 30 de Ag. de 2013
inline does not quite do the same thing as @. The two return different classes of object, which have different methods.
Azzi Abdelmalek
Azzi Abdelmalek el 30 de Ag. de 2013
Editada: Azzi Abdelmalek el 30 de Ag. de 2013
f2 is an inline class while f1 is a function_hundle class, but in the above example f1(x) and f2(x) give the same result.
Walter Roberson
Walter Roberson el 30 de Ag. de 2013
They do appear to give the same result in this case, but the effects of the two are not well enough documented to be able to tell if they would always give the same result. And in fact we can demonstrate that they do not.
f1 = inline('evalin(''caller'',''mfilename'')');
f2 = @(x) evalin('caller', 'mfilename');
now execute f1(1) and f2(1) and see that they give different outputs.

Iniciar sesión para comentar.

Categorías

Más información sobre Function Creation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de Ag. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by