-3

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

starrr
  • 1,013
  • 1
  • 17
  • 48

2 Answers2

4

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.

bla
  • 25,846
  • 10
  • 70
  • 101
3

You can use anonymous functions:

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

ans =

     8
Marcin
  • 215,873
  • 14
  • 235
  • 294