0

Lets say

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

And I want to integrate f for x in [0,1]. It seems like I have to define g and do quad(g,0,1)

 g=@(x) f(x,y,z); 
 quad(g,0,1)

The question I have is whether it is possible to do quad on f directly without defining a new function.

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
Galaxy5727
  • 45
  • 1
  • 1
  • 4

1 Answers1

1

Yes ; you can use the anonymous function directly as an argument.

quad(@(x)f(x,y,z),0,1);
Jacob
  • 34,255
  • 14
  • 110
  • 165