Getting integrand error from triple integral code code
Afficher commentaires plus anciens
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);
Réponses (1)
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));
1 commentaire
Alexander
le 28 Avr 2024
Catégories
En savoir plus sur Calculus dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!