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
Asked
Active
Viewed 693 times
-3
-
2The keyword you are looking for is `function handle`. Feel free to add `MATLAB` into it. – Divakar May 22 '14 at 07:00
2 Answers
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