Path: news.mathworks.com!not-for-mail
From: "ghasem " <shaban_sadeghi@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how import a variable from script file to function file?
Date: Wed, 15 May 2013 16:31:10 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 54
Message-ID: <kn0d8e$q92$1@newscl01ah.mathworks.com>
References: <kmvd13$jrv$1@newscl01ah.mathworks.com> <kn06bn$2qf$1@newscl01ah.mathworks.com>
Reply-To: "ghasem " <shaban_sadeghi@yahoo.com>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1368635470 26914 172.30.248.46 (15 May 2013 16:31:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 15 May 2013 16:31:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 4223132
Xref: news.mathworks.com comp.soft-sys.matlab:795630

> 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 = 1-w(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 = 1-w(i)^2;
k2 = k1*sqrt(er);
g1 = er*sqrt(kz^2-k3^2).*besseli(1,sqrt(-kz^2-k2^2)).*besselk(0,sqrt(-kz^2-k3^2))+... sqrt(-kz^2-k2^2).*besseli(0,sqrt(-kz^2-k2^2)).*besselk(1,sqrt(-kz^2-k3^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 "1-w(i)^2" formula within my function file?
please help me...