Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


ghasem
Posts:
99
Registered:
4/13/13


Re: how import a variable from script file to function file?
Posted:
May 15, 2013 12:31 PM


> See the Note box in the Description section of the documentation page for > FSOLVE for a description of different ways to pass extra parameters into the > function that you specify as the first input argument to FSOLVE. > > http://www.mathworks.com/help/optim/ug/fsolve.html > >  > Steve Lord > slord@mathworks.com > To contact Technical Support use the Contact Us link on > http://www.mathworks.com =========================== I didn't understand,exactly.namely,I have to add a input argument in FSOLVE that include in "i" index values,when call my_function_name?namely I have to write as following? equ1 = fsolve(@my_function_name , my_guess,i); ======== but I receive following error: ??? Undefined function or variable 'i'. Error in ==> my_function_name at 51 er = 1w(i)^2;
Error in ==> fsolve at 248 fuser = feval(funfcn{3},x,varargin{:});
Error in ==> my_script at 26 equ1 = fsolve(@my_func_name,my_guess,i); ============= again,I write total of my code (function and script) as following:
% first : I wrote function section as following:
function output = my_func_name(inputs) realPartOfInput = inputs(1); imagPartOfInput = inputs(2); % k1 , k2 , are known.and w is a vector that length(w)=100. % namely : w =linspace(1,5,100); kz = complex(realPartOfInput, imagPartOfInput); er = 1w(i)^2; k2 = k1*sqrt(er); g1 = er*sqrt(kz^2k3^2).*besseli(1,sqrt(kz^2k2^2)).*besselk(0,sqrt(kz^2k3^2))+... sqrt(kz^2k2^2).*besseli(0,sqrt(kz^2k2^2)).*besselk(1,sqrt(kz^2k3^2)); output = [ real(g1); imag(g1)];
% and saved above function in a directory. % second: I wrote a script that has a "for loop" for different initial guess: for i =1:100 real_guess(i) = i/100; imag_guess(i) = i/500; my_guess = [ real_guess(i) , imag_guess(i)] equ1 = fsolve(@my_function_name , my_guess); ... end % and saved this script same directory with function path. ==================== NOW,how transfer "i" index value in script to "i" index in "1w(i)^2" formula within my function file? please help me...



