Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to define the function $f(x,y)=\left ( xy,x-y^2,3x-2y \right )$, how can I do this in Matlab?


share|cite|improve this question
up vote 4 down vote accepted

Another possibility:

function [a,b,c] = fun1(x,y)



c = 3*x-2*y;

Save this as "fun1.m" (in your work directory). Now you can for example calculate


share|cite|improve this answer

How about

f = @(x,y) [x*y, x - y^2, 3*x - 2*y] ;

share|cite|improve this answer
It may be better to use .* operators if any matrix operations are extected to be computed elementwise. – Daryl Nov 10 '12 at 13:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.