Confusion with function handles
Show older comments
Greetings all,
This is the second part of what I am trying to work out, and I am new to function handles (i.e, @f, if you will). I'm trying to use three programs scripts at once, since someone told me it was best to do it this way, but I'm not seeing it. I'm open to suggestions, but I am seeing an error.
The first script I have contains the line:
R(D,:) = (V_1*F_1 - r)/(V_1*F_1 + r);
where all the terms are defined, and "r" is imaginary (as this issue was resolved yesterday - shout out to Walter Roberson).
I was told to invoke my second script (titled hankel0.m) at the command prompt, but that I had to define a function f.m first (my third script).
So my f.m file contains:
function f=f(r)
f=R(D,r)*r^2*exp(-r*A)
where R(D,r) = R(D,:) = (V_1*F_1 - r)/(V_1*F_1 + r), r is imaginary, and A is a constant - all of these are in the first script. and at the command prompt I say
>>z=hankel0(@f,B)
to invoke the call to hankel0.m, and B is a constant previously defined in my first script as well (and shows up in the variable space).
When I run the command above, I get an "Undefined function or variable 'D'" error. Now, 'D' is defined in my first script as well, and is in the variable space (it's an array of positive integers) since I ran the first script prior to invoking a hankel0 function call at the command prompt.
Obviously I'm doing something wrong, and I am new to function handles. Can anyone break it down for me? Again, I am new to function handles, so go easy on me.
Thanks!
5 Comments
Jesse
on 26 Jul 2012
Walter Roberson
on 26 Jul 2012
The question was reformatted only.
Jesse
on 26 Jul 2012
per isakson
on 26 Jul 2012
Edited: per isakson
on 26 Jul 2012
Do we agree that a main function is defined in an m-file as
function out = func_name( in )
code
end
and that a script is defined in an m-file as
code
?
You cannot invoke a script (as defined above) with input arguments!
Thus, hankel0 is that a script or function?
Jesse
on 26 Jul 2012
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!