MATLAB Function (Solving an Error)

后端 未结 3 2036
走了就别回头了
走了就别回头了 2021-01-29 14:57

I have one file with the following code:

function fx=ff(x)
fx=x;

I have another file with the following code:

function g = Lapl         


        
3条回答
  •  盖世英雄少女心
    2021-01-29 15:03

    Looks like what you're trying to do is create a function in the variable g. That is, you want the first line to mean,

    "Let g(x) be a function that is calculated like this: ff(x)*exp(-s*x)",

    rather than

    "calculate the value of ff(x)*exp(-s*x) and put the result in g".

    Solution

    You can create a subfunction for this

    function result = g(x)
      result = ff(x) * exp(-s * x);
    end
    

    Or you can create an anonymous function

    g = @(x) ff(x) * exp(-s * x);
    

    Then you can use g(a), g(b), etc to calculate what you want.

提交回复
热议问题