How can i use integral2 for a vector-valued function ? help please...

5 views (last 30 days)
for example i wrote this code:
%
f=@(x,y)x+y;
g=@(x,y)x^2+y^2;
h=@(x,y)x/y+y/x;
w=@(x,y)sin(x)+cos(y);
box=@(x,y)[f(x,y) g(x,y);h(x,y) w(x,y)];
answers=integral2(box,1,2,1,2)
i expected answers to be a 2*2 scalar matrix but i got only error... what to do?
hint:
Here f,g,h,w and their boundary conditions were only some simple examples.In my real code they are not only too complicated but also inseparable from their vector-valued function unless i define x,y as symbloic variables and separate them by calling function in symbolic variables( i do not want this because its too slow...). I also tested using integral twice instead of integral2 but this method was very very slow too.
my whole code depends on this integral and using reported methods cost me lots of time :(
i wonder why MATLAB does not support 'ArrayValued' option for integral2 :(
what can i do now ?

Answers (1)

Star Strider
Star Strider on 8 Sep 2015
In a word, No! The integral2 function does not support array-valued functions.
I thought we covered this in your previous Question: how can i use integral2 for a vector-valued function ?.
Please post the code for a function you want to integrate in your ‘real code’. What about it conforms to the integral function definition of 'ArrayValued'?
  2 Comments
meysam esmaeeli
meysam esmaeeli on 9 Sep 2015
OK.this is the code for calculation of the function I want to integrate:
% code
clear all
clc
% initial values
r=24;t=37.5;L=134;w=114;
E1=55*10^9;E2=10.4*10^9;E3=10.4*10^9;G12=4.3*10^9;G13=4.3*10^9;G23=3.5*10^9;v12=0.28;v13=0.28;v23=0.5;
Er=4.44*10^9;Gr=1.65*10^9;vr=0.34;
E1p=144*10^9;E2p=7.31*10^9;E3p=7.31*10^9;G12p=4.45*10^9;G13p=4.45*10^9;G23p=2.65*10^9;v12p=0.25;v13p=0.25;v23p=0.39;
h=2.5*r;l=(0.98/0.24)*r;
% boundaries
f1=@(x,y)0.5*t*(cos(pi*x/L)+cos(pi*y/w)+2);
DIFFf1_x=@(x)-pi*0.5*t*(sin(pi*x/L))/L;
f2=@(x,y)0.5*t*(cos(pi*x/L)-cos(pi*y/w)+2);
f2prime=@(x,y)0.5*t*(cos(pi*x/w)-cos(pi*y/L)+2);
f3=@(x,y)0.5*t*(-cos(pi*x/w)-cos(pi*y/L)+2);
% myfunction calculation
S=[1/E1 -v12/E1 -v13/E1 0 0 0;-v12/E1 1/E2 -v23/E2 0 0 0;-v13/E1 -v23/E2 ...
1/E3 0 0 0;0 0 0 1/G23 0 0;0 0 0 0 1/G13 0;0 0 0 0 0 1/G12];
teta1=@(v,x)atan((-pi*r/l)*(1-2*v/h)*sin((pi/l)*x));
teta3=@(x)atan(DIFFf1_x(x));
Vw=@(x,y)(f1(x,y)-f2(x,y))/(2*t);
Vf=@(x,y)(f2prime(x,y)-f3(x,y))/(2*t);
Vr=@(x,y)1-Vf(x,y)-Vw(x,y);
TPw=@(v,x,y)[Vw(x,y)*(cos(teta1(v,x)))^2 Vw(x,y)*(sin(teta1(v,x)))^2 0 0 ...
0 Vw(x,y)*2*cos(teta1(v,x))*sin(teta1(v,x));(sin(teta1(v,x)))^2 ...
(cos(teta1(v,x)))^2 0 0 0 -2*cos(teta1(v,x))*sin(teta1(v,x)); 0 0 1 0 0 ...
0;0 0 0 Vr(x,y)*cos(teta1(v,x)) -sin(teta1(v,x)) 0;0 0 0 ...
Vf(x,y)*sin(teta1(v,x)) cos(teta1(v,x)) 0;-Vf(x,y)*cos(teta1(v,x))*...
sin(teta1(v,x)) cos(teta1(v,x))*sin(teta1(v,x)) 0 0 0 ...
(cos(teta1(v,x)))^2-(sin(teta1(v,x)))^2];
TWw=@(x,y)[(cos(teta3(x)))^2 0 Vf(x,y)*(sin(teta3(x)))^2...
0 2*cos(teta3(x))*sin(teta3(x)) 0;0 1 0 0 0 0;(sin(teta3(x)))^2 0...
(cos(teta3(x)))^2 0 -2*cos(teta3(x))*sin(teta3(x)) 0;0 0 0...
cos(teta3(x)) 0 -sin(teta3(x));-cos(teta3(x))*sin(teta3(x)) 0 ...
cos(teta3(x))*sin(teta3(x)) 0 (cos(teta3(x)))^2-(sin(teta3(x)))^2...
0;0 0 0 Vr(x,y)*sin(teta3(x)) 0 Vr(x,y)*cos(teta3(x))];
inTWw=@(x,y)inv(TWw(x,y));
inTPw=@(v,x,y)inv(TPw(v,x,y));
SWw=@(x,y)inTWw(x,y)*S*TWw(x,y);
SPWw=@(v,x,y)(inTPw(v,x,y)*inTWw(x,y))*S*(TWw(x,y)*TPw(v,x,y));
SWf=@(x,y)SWw(y,x);
SPWf=@(u,x,y)SPWw(u,x,y);
% my final function
myfunction=@(u,v,x,y)(SPWw(v,x,y)*SPWf(u,x,y)*SWw(x,y)*SWf(x,y))./(x^2+y^2);
so this way i calculate my function and now i want to integrate it in a code like this but i can not :(
% integrate code
Y=@(x)r*cos((pi/l)*x);
sum=0;
for i=0:(h/2)/1000:h/2
for j=0:(h/2)/10:h/2
sum=sum+integral2(@(x,y)myfunction(i,j,x,y),1,10,1,Y);
end
end
what should I do now? I need a fast method...
Star Strider
Star Strider on 9 Sep 2015
Your code is difficult for me to follow. I also do not know whether you intend matrix or array (element-wise) operations in your code. (See the documentation on Array vs. Matrix Operations for details.)
It is best that you not use the inv function. Use the mldivide (or (\)) function instead.
Many of the elements appear to be matrices, and you cannot use integral2 to integrate 'ArrayValued' functions. You have to use iterated calls to integral instead, with 'ArrayValued',1 as arguments to it, but only if it matches the definition of 'ArrayValued' in integral. You might have to integrate the individual elements of your matrix separately, as I did with your example code, then reassemble them into your result matrix in the end.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!