integral2 for a non-scalar matlabFunction

조회 수: 2 (최근 30일)
Mojtaba Norouzisadeh
Mojtaba Norouzisadeh 2023년 7월 16일
편집: Torsten 2023년 7월 16일
I'm trying to use integral2 for a non-scalar matlab function. In the following I define 3 symbolic functions, put 5 set of data for (y1, y2 and y3) , which in total makes it 15 functions. I convert them into anonymous function with "matlabFunction" so that I could use the integral2. The problem is integral2 is not working with this output. Is there a way around it ? The purpose is to vectorized the operation of integration to speed up the code.
syms zi eta
syms N1 N2 N3
syms y_1 y_2 y_3
N1=1-zi-eta;
N2=zi;
N3=eta;
N=[N1,N2,N3];
for i=1:3
cons_int(i)=N(i)*sinh(y_1.*N1+y_2.*N2+y_3.*N3);
end
y_1_val=[1:5]';
y_2_val=[1:5]';
y_3_val=[1:5]';
intagrand_temp=subs(cons_int,{y_1, y_2, y_3},{y_1_val,y_2_val,y_3_val});
if ~isempty(intagrand_temp)
intagrand_1 = matlabFunction(intagrand_temp);
zi_max = @(eta) 1 - eta;
q_cons = integral2(intagrand_1,0,1,0,zi_max);
end
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.

Error in symengine>@(eta,zi)reshape([-sinh(1.0).*(eta+zi-1.0),-sinh(2.0).*(eta+zi-1.0),-sinh(3.0).*(eta+zi-1.0),-sinh(4.0).*(eta+zi-1.0),-sinh(5.0).*(eta+zi-1.0),zi.*sinh(1.0),zi.*sinh(2.0),zi.*sinh(3.0),zi.*sinh(4.0),zi.*sinh(5.0),eta.*sinh(1.0),eta.*sinh(2.0),eta.*sinh(3.0),eta.*sinh(4.0),eta.*sinh(5.0)],[5,3])

Error in integral2Calc>integral2t/tensor (line 228)
Z = FUN(X,Y); 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 integral2 (line 105)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);

답변 (1개)

Torsten
Torsten 2023년 7월 16일
이동: Torsten 2023년 7월 16일
"intagrand_temp" is a 5x3 matrix of symbolic functions in eta and zi. I don't understand which scalar-valued function(s) you want to integrate. Each of the 15 functions one by one to get a 5x3 matrix as result ?
Maybe like this ?
syms zi eta
syms N1 N2 N3
syms y_1 y_2 y_3
N1=1-zi-eta;
N2=zi;
N3=eta;
N=[N1,N2,N3];
for i=1:3
cons_int(i)=N(i)*sinh(y_1.*N1+y_2.*N2+y_3.*N3);
end
y_1_val=[1:5]';
y_2_val=[1:5]';
y_3_val=[1:5]';
intagrand_temp=subs(cons_int,{y_1, y_2, y_3},{y_1_val,y_2_val,y_3_val})
intagrand_temp = 
q_cons = int(int(intagrand_temp,zi,0,1-eta),eta,0,1)
q_cons = 
  댓글 수: 6
Mojtaba Norouzisadeh
Mojtaba Norouzisadeh 2023년 7월 16일
Thanks for the answer. I think my other option is to use parfor loop.
Torsten
Torsten 2023년 7월 16일
편집: Torsten 2023년 7월 16일
Yes, that's true. These are 15 independent integrations that should be possible to be run in parallel.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by