Getting integrand error from triple integral code code

16 views (last 30 days)
Alexander
Alexander on 17 Apr 2024 at 0:20
Commented: Alexander on 28 Apr 2024 at 1:36
Code:
% Define the function to integrate
f = @(x, y, z) 1;
% Define the bounds
xmin = -2;
xmax = 2;
% Define ymin and ymax as functions of x
ymin = @(x) -sqrt((4 - x.^2)./3);
ymax = @(x) sqrt((4 - x.^2)./3);
% Define zmin and zmax as functions of x and y
zmin = @(x, y) 4 - x.^2 - 3.*y.^2;
zmax = @(x, y) x.^2 + y.^2;
% Perform the triple integral
result = integral3(@(x,y,z) f(x,y,z), xmin, xmax, ymin, ymax, zmin, zmax);
Error:
Error using integral2Calc>tensor (line 253)
Integrand output size does not match the input size.
Error in integral2Calc>integral2t (line 55)
[Qsub,esub,FIRSTFUNEVAL,NFE] = tensor(thetaL,thetaR,phiB,phiT,[],[], ...
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral3>innerintegral (line 128)
Q1 = integral2Calc( ...
Error in integral3>@(x)innerintegral(x,fun,yminx,ymaxx,zminxy,zmaxxy,integral2options) (line 111)
f = @(x)innerintegral(x, fun, yminx, ymaxx, ...
Error in integralCalc>iterateScalarValued (line 334)
fx = FUN(t);
Error in integralCalc>vadapt (line 148)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen, ...
Error in integralCalc (line 77)
[q,errbnd] = vadapt(vfunAB,interval, ...
Error in integral3 (line 113)
Q = integralCalc(f,xmin,xmax,integralOptions);
Error in Calc3Project3AlexDavies (line 18)
result = integral3(@(x,y,z) f(x,y,z), xmin, xmax, ymin, ymax, zmin, zmax);

Answers (1)

Torsten
Torsten on 17 Apr 2024 at 0:29
Edited: Torsten on 17 Apr 2024 at 0:30
f must return a vector of ones of the same size as the inputs x, y or z (which all have the same sizes).
Thus replace
f = @(x, y, z) 1
by
f = @(x, y, z) ones(size(x));

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!