0

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

Thanks!

DonAntonio
  • 211,718
  • 17
  • 136
  • 287
Tina
  • 517

2 Answers2

8

How about

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

littleO
  • 51,938
  • 4
    It may be better to use .* operators if any matrix operations are extected to be computed elementwise. – Daryl Nov 10 '12 at 13:09
4

Another possibility:


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

a=x*y;

b=x-y.^2;

c = 3*x-2*y;


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

fun1(3,2)

saz
  • 120,083