http://www.mathworks.com/matlabcentral/newsreader/view_thread/318467
MATLAB Central Newsreader  help with double integration
Feed for thread: help with double integration
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Thu, 29 Mar 2012 01:26:18 +0000
help with double integration
http://www.mathworks.com/matlabcentral/newsreader/view_thread/318467#871532
prabhakaran m
need help to solve double integration. i have to calculate the fourier constant using the formula.<br>
<br>
A(m,n)= double integration of w(x,y)*cos(m*y/r)*cos(2*n*pi*x/L)in the limits(0,L,0,2*pi*R) i have the matrix w(x,y) of size 74*17 and A will also be in the size of 74*17. but i am puzzled with the number of for loops i have to use. here m and n in the formula is also constants m form 1 to 74 and n form 1 to 17. R is radius. L is the length.<br>
<br>
been puzzled here. the code below<br>
<br>
out = integrnd(x,y);<br>
<br>
A(m,n)= w(x,y)*cos(m*y/r)*cos(2*n*pi*x/l);<br>
<br>
result = dblquad(@integrnd,0,l,0,2*pi*R);<br>
<br>
i know there is big mistake in the code. by seeing the double integration help file, i have did the above part. if somebody helps me with the loops it will be of great help.

Thu, 29 Mar 2012 02:24:28 +0000
Re: help with double integration
http://www.mathworks.com/matlabcentral/newsreader/view_thread/318467#871535
prabhakaran m
x=linespace(0,L,16);<br>
y=linespace(0,2*pi*R,72)<br>
<br>
for ii=1:length(x)<br>
for jj=1:length(y)<br>
const=0.0;<br>
for m=1:16<br>
for n=1:74<br>
I_term=w(ii,jj)*cos((n1)*theta(ii))*cos(2*(m1)*pi*v(jj)/h); <br>
const=const+I_term;<br>
end<br>
end<br>
result(m,n)=const;<br>
end<br>
end<br>
<br>
I2 = trapz(y,trapz(x,result))<br>
<br>
working around the clock i have did upto this. here I2 should also be in the array size of (14,74) but i am getting the error like this<br>
<br>
??? Error using ==> trapz<br>
LENGTH(X) must equal the length of the first nonsingleton dimension of Y.<br>
what might be the problem

Thu, 29 Mar 2012 02:52:22 +0000
Re: help with double integration
http://www.mathworks.com/matlabcentral/newsreader/view_thread/318467#871537
prabhakaran m
"prabhakaran m" <prabha.gahon@gmail.com> wrote in message <jl0h4s$pht$1@newscl01ah.mathworks.com>...<br>
> <br>
sorry typo error in above message the I2 array shd be in the size of same as w(i,j)<br>
otherwise ignore the above message. look at this<br>
<br>
<br>
L=150;<br>
R=(94.6/2+.5); %reference radius<br>
x=0:10:150;<br>
y=0:5:360;<br>
<br>
for ii=1:length(x)<br>
for jj=1:length(y)<br>
const=0.0;<br>
for m=1:72<br>
for n=1:15<br>
I_term=w(ii,jj)*cos((m1)*y(jj)/R)*cos(2*(n1)*pi*x(ii)/L); <br>
const=const+I_term;<br>
end<br>
end<br>
result(ii,jj)=const;<br>
end<br>
end<br>
<br>
if i execute upto here i am getting <br>
Index exceeds matrix dimensions this error<br>
<br>
i know i have just misplaced the i, j , ii and jj. any help with that will be very helpful.<br>
<br>
after that i have to calculate I2 which is<br>
<br>
I2 = trapz(y,trapz(x,result))<br>
<br>
> sorry for repeated post. couldnt deny it.

Thu, 29 Mar 2012 03:05:23 +0000
Re: help with double integration
http://www.mathworks.com/matlabcentral/newsreader/view_thread/318467#871539
Roger Stafford
"prabhakaran m" <prabha.gahon@gmail.com> wrote in message <jl0dnq$g19$1@newscl01ah.mathworks.com>...<br>
> need help to solve double integration. i have to calculate the fourier constant using the formula.<br>
> <br>
> A(m,n)= double integration of w(x,y)*cos(m*y/r)*cos(2*n*pi*x/L)in the limits(0,L,0,2*pi*R) i have the matrix w(x,y) of size 74*17 and A will also be in the size of 74*17. but i am puzzled with the number of for loops i have to use. here m and n in the formula is also constants m form 1 to 74 and n form 1 to 17. R is radius. L is the length.<br>
> <br>
> been puzzled here. the code below<br>
> <br>
> out = integrnd(x,y);<br>
> <br>
> A(m,n)= w(x,y)*cos(m*y/r)*cos(2*n*pi*x/l);<br>
> <br>
> result = dblquad(@integrnd,0,l,0,2*pi*R);<br>
> <br>
> i know there is big mistake in the code. by seeing the double integration help file, i have did the above part. if somebody helps me with the loops it will be of great help.<br>
        <br>
Prabhakaran, isn't this essentially the same question you asked back in 18 Sep 2010 in the thread:<br>
<br>
<a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/288859">http://www.mathworks.com/matlabcentral/newsreader/view_thread/288859</a> ?<br>
<br>
I still think the answer to your question lies in that thread. You should reread it over carefully. As was pointed out there, your problem is unsuited for 'dblquad' or any of the other quadrature routines that require a function handle for the integrand. Only routines like 'trapz' or others of higher order in the File Exchange that deal with discrete data can be used for this purpose.<br>
<br>
The difficulty with integrating functions that are only defined on a discrete set of points is that there is uncertainty about the integrand values in between these points. In trapezoidal integration techniques these values are approximated by straight lines connecting the values at the discrete points. With higher order routines, polynomials of various orders are used which run through these points, and this sometimes yields more reasonable approximations. However, you cannot ever expect to obtain precise values with such techniques. This is inherent in the lack of knowledge about integrand values between the points. It is the same problem that faces anyone who does interpolation between points of discretely defined data.<br>
<br>
Roger Stafford

Thu, 29 Mar 2012 03:45:26 +0000
Re: help with double integration
http://www.mathworks.com/matlabcentral/newsreader/view_thread/318467#871541
prabhakaran m
"Roger Stafford" wrote in message <jl0jhj$30i$1@newscl01ah.mathworks.com>...<br>
> "prabhakaran m" <prabha.gahon@gmail.com> wrote in message <jl0dnq$g19$1@newscl01ah.mathworks.com>...<br>
> > need help to solve double integration. i have to calculate the fourier constant using the formula.<br>
> > <br>
> > A(m,n)= double integration of w(x,y)*cos(m*y/r)*cos(2*n*pi*x/L)in the limits(0,L,0,2*pi*R) i have the matrix w(x,y) of size 74*17 and A will also be in the size of 74*17. but i am puzzled with the number of for loops i have to use. here m and n in the formula is also constants m form 1 to 74 and n form 1 to 17. R is radius. L is the length.<br>
> > <br>
> > been puzzled here. the code below<br>
> > <br>
> > out = integrnd(x,y);<br>
> > <br>
> > A(m,n)= w(x,y)*cos(m*y/r)*cos(2*n*pi*x/l);<br>
> > <br>
> > result = dblquad(@integrnd,0,l,0,2*pi*R);<br>
> > <br>
> > i know there is big mistake in the code. by seeing the double integration help file, i have did the above part. if somebody helps me with the loops it will be of great help.<br>
>         <br>
> Prabhakaran, isn't this essentially the same question you asked back in 18 Sep 2010 in the thread:<br>
> <br>
> <a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/288859">http://www.mathworks.com/matlabcentral/newsreader/view_thread/288859</a> ?<br>
> <br>
> I still think the answer to your question lies in that thread. You should reread it over carefully. As was pointed out there, your problem is unsuited for 'dblquad' or any of the other quadrature routines that require a function handle for the integrand. Only routines like 'trapz' or others of higher order in the File Exchange that deal with discrete data can be used for this purpose.<br>
> <br>
> The difficulty with integrating functions that are only defined on a discrete set of points is that there is uncertainty about the integrand values in between these points. In trapezoidal integration techniques these values are approximated by straight lines connecting the values at the discrete points. With higher order routines, polynomials of various orders are used which run through these points, and this sometimes yields more reasonable approximations. However, you cannot ever expect to obtain precise values with such techniques. This is inherent in the lack of knowledge about integrand values between the points. It is the same problem that faces anyone who does interpolation between points of discretely defined data.<br>
> <br>
> Roger Stafford<br>
<br>
yes Roger, its the same question i asked a year and half back. now i again started to do it. yes that thread was excellent by reading that thread only i found i should not use dblquad. rather trapz is the thing i have to deal with.<br>
<br>
i have did the code <br>
<br>
L=150;<br>
R=(94.6/2+.5); %reference radius<br>
x=0:10:150;<br>
y=0:5:360;<br>
theta=y*pi/180;<br>
lentheta=length(theta);<br>
result=[];<br>
for ii=1:length(x)<br>
for jj=1:lentheta<br>
const=0.0;<br>
for m=1:72<br>
for n=1:15<br>
I_term=w(ii,jj)*cos((m1)*y(jj)/R)*cos(2*(n1)*pi*x(ii)/L); <br>
const=const+I_term;<br>
end<br>
end<br>
result(ii,jj)=const;<br>
end<br>
end<br>
i2 = [];<br>
for i=1:length(x)<br>
for j=1:lentheta<br>
I2(i,j) =(2/pi*L)* trapz(y,trapz(x,result));<br>
end <br>
end<br>
<br>
and i have successfully arrived with the solution. also i am sure the solution what i have got is write or wrong. but i feel odd i might have misplaced the i,j,ii and jj. if you find any mistake can u tell me.