Results 1 to 3 of 3

Math Help - In Matlab, how to refer a self-defined function in another self-defined function?

  1. #1
    Newbie
    Joined
    Nov 2008
    Posts
    8

    In Matlab, how to refer a self-defined function in another self-defined function?

    Dear all,

    I have a question on Matlab: when I define a new function in Matlab, I want to use another function defined by myself previously as an input argument, how can I do that?

    To be more specific, suppose I have defined a function, say f(x). Now I am going to define a new function g(x)=f(x)+x and using f(x) as one of the input argument in my definition of g(x).

    Is there anybody who can help me on this? Thanks a lot in advance.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by analysismath View Post
    Dear all,

    I have a question on Matlab: when I define a new function in Matlab, I want to use another function defined by myself previously as an input argument, how can I do that?

    To be more specific, suppose I have defined a function, say f(x). Now I am going to define a new function g(x)=f(x)+x and using f(x) as one of the input argument in my definition of g(x).

    Is there anybody who can help me on this? Thanks a lot in advance.
    Define the second function as:

    Code:
    function rv=g(ff,x)
      rv=ff(x)+x;
    Then call with:

    Code:
    y=g(@f,x);
    In the calling code @f is the function handle for the function f.

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Nov 2008
    Posts
    8

    Thumbs up

    Thank you so much! It works perfectly as you said.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 0
    Last Post: October 19th 2011, 04:49 AM
  2. Well-defined function
    Posted in the Advanced Algebra Forum
    Replies: 1
    Last Post: October 4th 2010, 03:46 PM
  3. Well-Defined function
    Posted in the Advanced Algebra Forum
    Replies: 2
    Last Post: July 4th 2010, 04:11 AM
  4. function defined
    Posted in the Pre-Calculus Forum
    Replies: 2
    Last Post: July 4th 2006, 12:56 AM
  5. function defined
    Posted in the Pre-Calculus Forum
    Replies: 9
    Last Post: July 4th 2006, 12:52 AM

Search Tags


/mathhelpforum @mathhelpforum