integral2 for a non-scalar matlabFunction
Show older comments
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
Answers (1)
"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})
q_cons = int(int(intagrand_temp,zi,0,1-eta),eta,0,1)
6 Comments
Mojtaba Norouzisadeh
on 16 Jul 2023
Edited: Mojtaba Norouzisadeh
on 16 Jul 2023
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)
zi_max = @(eta) 1 - eta;
for i = 1:size(intagrand_temp,1)
for j = 1:size(intagrand_temp,2)
intagrand_1 = matlabFunction(intagrand_temp(i,j),'Vars',{eta,zi});
q_cons(i,j) = integral2(intagrand_1,0,1,0,zi_max);
end
end
end
q_cons
double(int(int(intagrand_temp,zi,0,1-eta),eta,0,1))
Mojtaba Norouzisadeh
on 16 Jul 2023
Mojtaba Norouzisadeh
on 16 Jul 2023
Categories
Find more on Conversion Between Symbolic and Numeric in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
