Anonymous Function with natural log inside

I am trying to make an anonymous function with a natural log inside. Here is my code:
p = @(h)29.921*(1 - 6.8753*10^-6.*h);
T = @(p)49.161*log(p) + 44.932;
h = -500:14439;
p(h);
T(p);
plot(h,T(p))
When I run it, I get this error:
Undefined function 'log' for input arguments of type 'function_handle'.
Error in Elevation>@(p)49.161*log(p)+44.932
Error in Elevation (line 10)
T(p);
Is it because p is an anonymous function, too? Or is it something else? How can I fix this?

 Respuesta aceptada

Star Strider
Star Strider el 18 de En. de 2018
Your functions are actually all functions of ‘h’. To refer to ‘p’ in ‘T’, you need to refer to it as ‘p(h)’.
This works:
p = @(h)29.921*(1 - 6.8753E-6.*h);
T = @(h)49.161*log(p(h)) + 44.932;
h = -500:14439;
p(h);
T(h);
plot(h,T(h))

2 comentarios

Anne Coleman
Anne Coleman el 18 de En. de 2018
Thank you so much!
Star Strider
Star Strider el 18 de En. de 2018
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming Utilities en Centro de ayuda y File Exchange.

Preguntada:

el 18 de En. de 2018

Comentada:

el 18 de En. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by