The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: how import a variable from script file to function file?
Replies: 3   Last Post: May 15, 2013 12:31 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 118
Registered: 4/13/13
Re: how import a variable from script file to function file?
Posted: May 15, 2013 12:31 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

> 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.
> --
> Steve Lord
> To contact Technical Support use the Contact Us link on

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);
% 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...

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.