How to extract values from a function handle in the prompt

Here is my code:
C1 = chebfun('exp(1i*t)*(2.4633+0.2865*cos(t)-0.2930*sin(t)-0.0378*cos(2*t)-0.0161*sin(2*t)-0.1422*cos(3*t)+0.0078*sin(3*t)-0.0418*cos(4*t)-0.0569*sin(4*t))',[0 2*pi],'trig');
C2 = chebfun('exp(1i*t)*(1.7133+0.2797*cos(t)-0.2480*sin(t)+0.0295*cos(2*t)+0.0460*sin(2*t)-0.1987*cos(3*t)+0.0309*sin(3*t)-0.0017*cos(4*t)+0.0471*sin(4*t))',[0 2*pi],'trig');
[finv]= conformal2(C1,C2,'poly', 'plots');
When I execute the commands and type in finv in the prompt to get my inverse function, the result is:
finv =
function_handle with value:
@(zz)reval(zz,z,f,w)
My question is how to extract finv from the above function handle?

 Accepted Answer

info = functions(finv);
ws = info.workspace{1};
ws.z
ws.f
ws.w
That will show you the variables that were "captured" in the function handle. It will not, however, necessarily show you anything recognizable as a formula.

10 Comments

@Walter Roberson, Thanks for the suggestion. It worked.
It is true, as you mentioned, that this gives me a bunch of coefficients for the inverse function of f. How can I get a formula for the inverse of the function f from the coefficients?
I do not find a conformal2() function to test with ?
conformal2 is actually a special code that deals with conformal mapping and is not available in MATLAB. I got it from Univesity of Oxford and due to copyright issues, I will not be able to share it here. Sorry about that.
But I can give an outline of what the code does.
It creates a conformal mapping between a deformed annulus and a perfect annulus. The forward mapping is f and its inverse is finv.
In my first post, C1 is the Fourier series approximation of the inner simple closed curve of the deformed annulus and C2 is the Fourier series approximation of the outer simple closed curve of the deformed annulus. So [finv] = conformal2() creates the inverse of the forward conformal mapping, i.e., the mapping from the perfect to the deformed annulus.
So I want to know how to create finv from a bunch of coefficients.
I apologize for not mentioning that conformal2 is not available in MATLAB.
It's a bit difficult for me to predict what the data structures look like in that situation.
Without access to the data structures and the code or documentation, about the best I could suggest would be to finv() a number of points and try to model the resulting function, perhaps with System Identification.
Yes, it is in fact difficult if the code is not there.
I will try your suggestion using System Identification.
Thanks for your help.
I have another problem with extracting values from function handles. The method that you suggested in the previous post are not working for this case.
I constructed a complex valued function that takes a vector of complex numbers and returns a vector of complex numbers. The function is defined as
function Z = inverseratappr(zz)
Now suppose I have a list of complex numbers x+1i*y, where x and y are list of numbers.
When I execute the code with
Z = inverseratappr(x+1i*y)
it gives me the following function handle
Z =
function_handle with value:
@(zz)inverseratappr(x+1i*y)
I tried almost all the suggestions on how to extract Z, but none seem to work. Can you suggest what should be done to get the list of Z values that the function returns?
That code does not return any Z values: it returns a function handle.
However, the function handle ignores its input, so just invoke it, Z() to see the return values.
I did try that. But it's giving me an unexpected error. There is a loop in my code, which is
for t = 0:0.001:2*pi % Covering all the values of theta
for r = r1:0.01:r2 % Spanning the annulus radially
x(1,n) = r*cos(t); % x-value for each coordinate on the annulus
y(1,n) = r*sin(t); % y-value for each coordinate on the annulus
n = n+1; % Updating n for registering the next x,y values
end
end
Now when I write Z() in the prompt, it gives me the error:
>> Z()
Undefined operator ':' for input arguments of type
'function_handle'.
Error in inverseratappr (line 26)
for r = r1:0.01:r2 % Spanning the annulus
radially
But I am suspecting that it is a different function handle that is involved. You were at the command prompt, so if it was Z that the error message was about, then you would not have received a traceback line. I suspect Z([]) is going to show the error as well.
You should debug,
dbstop if error
Z([])
and see where it stops. For example perhaps at the location indicated, it is expecting r1 and r2 to be numeric, but instead one of them is a function handle.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!