I am doing triple integration by matlab and some error displayed.

2 visualizaciones (últimos 30 días)
LA Leung
LA Leung el 31 de Mzo. de 2020
Comentada: LA Leung el 31 de Mzo. de 2020
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'.
Error in integral3>@(y,z)FUN(x(1)*ones(size(z)),y,z) (line 138)
@(y,z)FUN(x(1)*ones(size(z)),y,z), ...
Error in integral2Calc>integral2t/tensor (line 237)
Z1 = FUN(X(VTSTIDX),Y(VTSTIDX)); NFE = NFE + 1;
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral3/innerintegral (line 137)
Q1 = integral2Calc( ...
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral3 (line 121)
Q = integralCalc(@innerintegral,xmin,xmax,integralOptions);
I believe the frist error is caused by my constant setting, how to change the type of the constant type?
For me, I just input k=50 to do it. any advice to me?
  1 comentario
LA Leung
LA Leung el 31 de Mzo. de 2020
Also, if I input a very complicated formula when will the .* and ./ be used?

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 31 de Mzo. de 2020
Use the ^ operator when you want to perform matrix multiplication in raising the matrix to a power.
Use the .^ operator when you want to perform element-wise multiplication in raising each element in the array to a power.
A = [1 2; 3 4]
A^2 % equivalent of A * A, using matrix multiplication
A.^2 % equivalent of A .* A, using element-wise multiplication
Since integral3 is going to call your function with an array of data, you probably want to use the element-wise operators rather than the matrix operators in your function.
  4 comentarios
Steven Lord
Steven Lord el 31 de Mzo. de 2020
Re: ordering
The integral3 function doesn't really care what variable names you use as the inputs for your integrand function so long as the first set of limits corresponds to the limits of the first input argument to your integrand, the second to the second, and the third to the third. So if your integrand computes f(y, x, z) then the first set of limits are the limits of the integral over y, the second the limits over x, and the third the limits over z.
See the "4-D Integral of Sphere" example on the integral3 documentation page and note that the integral3 call in the function handle Q integrates over theta, then phi, then xi.
Re: vectorizing
The only multiplication or power operator in that integrand that doesn't need to be element-wise is the one between c and y, and it doesn't really matter whether that's matrix or element-wise multiplication. If one or both of a and b in the expression a*b is scalar it's equivalent to a.*b and I'm assuming your statement "c is constant" means that it's a scalar constant.
LA Leung
LA Leung el 31 de Mzo. de 2020
If I want to see the shape of function after second integral, how can I plot it? the integration order of f(y,x,z) is (y>x>z), can I do that f(z)=@(z) integral2(f,ymin,ymax,xmin,xmax)? because I try this and I can't plot it.

Iniciar sesión para comentar.

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by