Search code examples
matlabfunction-handle

Calculate function in matlab


is there any way to calculate a function in matlab using toolbox? for example I have this function: f(x,y)=x^2+y^2, I want to set x=2 and y=2 and function take back 8. How can I do it? Thanks


Solution

  • you can use anonymous functions, for example:

    f=@(x,y)x.^2+y.^2;
    

    or just write a file for example abc.m that has this code:

     function f=abc(x,y)
     f= x.^2+y.^2;
    

    then abc(2,2) will return the answer if the function file is at the path.