-1
$\begingroup$

I want to evaluate the $\int\int\int dxdydz$ using 'integral3' function in MATLAB. But the only code my intuition has helped me it this:

g = @(x,y,z) 1
u = integral3(g,1,2,1,3,1,4)

But this results in errors. Please help me create the correct code.

$\endgroup$
1
  • 1
    $\begingroup$ what kind of errors are you getting? $\endgroup$
    – Dylan
    Apr 26, 2018 at 12:56

2 Answers 2

3
$\begingroup$

integral3 expects the function g to be vectorized, however, g = @(x,y,z) 1 will always return a scalar, no matter the dimensions of the input x, y, or z.

A simple fix:

g = @(x,y,z) 1 + 0*x
u = integral3(g,1,2,1,3,1,4)

Another example

g = @(x,y,z) x.*y
u = integral3(g,1,2,1,3,1,4)
$\endgroup$
1
  • $\begingroup$ Thanks for the explanation, It worked! $\endgroup$ May 26, 2018 at 7:32
-2
$\begingroup$
clear all
clc
syms x y z
xa=-2;
xb=2;
ya=-sqrt(2-x^2/2);
yb=sqrt(2-x^2/2);
za=x^2+3*y^2;
zb=8-x^2-y^2;
I=int(int(int(1+0*z,z,za,zb),y,ya,yb),x,xa,xb)
viewSolid(z,za,zb,y,ya,yb,x,xa,xb)
$\endgroup$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .