Confusion with function handles
古いコメントを表示
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 件のコメント
Jesse
2012 年 7 月 26 日
Walter Roberson
2012 年 7 月 26 日
The question was reformatted only.
Jesse
2012 年 7 月 26 日
per isakson
2012 年 7 月 26 日
編集済み: per isakson
2012 年 7 月 26 日
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
2012 年 7 月 26 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!