Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
help with double integration

Subject: help with double integration

From: prabhakaran m

Date: 29 Mar, 2012 01:26:18

Message: 1 of 5

need help to solve double integration. i have to calculate the fourier constant using the formula.

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.

been puzzled here. the code below

out = integrnd(x,y);

A(m,n)= w(x,y)*cos(m*y/r)*cos(2*n*pi*x/l);

result = dblquad(@integrnd,0,l,0,2*pi*R);

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.

Subject: help with double integration

From: prabhakaran m

Date: 29 Mar, 2012 02:24:28

Message: 2 of 5

x=linespace(0,L,16);
y=linespace(0,2*pi*R,72)
      
for ii=1:length(x)
  for jj=1:length(y)
    const=0.0;
for m=1:16
    for n=1:74
        I_term=w(ii,jj)*cos((n-1)*theta(ii))*cos(2*(m-1)*pi*v(jj)/h);
        const=const+I_term;
    end
end
result(m,n)=const;
end
end
        
 I2 = trapz(y,trapz(x,result))

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

??? Error using ==> trapz
LENGTH(X) must equal the length of the first non-singleton dimension of Y.
what might be the problem

Subject: help with double integration

From: prabhakaran m

Date: 29 Mar, 2012 02:52:22

Message: 3 of 5

"prabhakaran m" <prabha.gahon@gmail.com> wrote in message <jl0h4s$pht$1@newscl01ah.mathworks.com>...
>
 sorry typo error in above message the I2 array shd be in the size of same as w(i,j)
otherwise ignore the above message. look at this


L=150;
R=(94.6/2+.5); %reference radius
x=0:10:150;
y=0:5:360;
      
for ii=1:length(x)
  for jj=1:length(y)
    const=0.0;
for m=1:72
    for n=1:15
        I_term=w(ii,jj)*cos((m-1)*y(jj)/R)*cos(2*(n-1)*pi*x(ii)/L);
        const=const+I_term;
    end
end
result(ii,jj)=const;
end
end

if i execute upto here i am getting
Index exceeds matrix dimensions this error

i know i have just misplaced the i, j , ii and jj. any help with that will be very helpful.

after that i have to calculate I2 which is

 I2 = trapz(y,trapz(x,result))

> sorry for repeated post. couldnt deny it.

Subject: help with double integration

From: Roger Stafford

Date: 29 Mar, 2012 03:05:23

Message: 4 of 5

"prabhakaran m" <prabha.gahon@gmail.com> wrote in message <jl0dnq$g19$1@newscl01ah.mathworks.com>...
> need help to solve double integration. i have to calculate the fourier constant using the formula.
>
> 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.
>
> been puzzled here. the code below
>
> out = integrnd(x,y);
>
> A(m,n)= w(x,y)*cos(m*y/r)*cos(2*n*pi*x/l);
>
> result = dblquad(@integrnd,0,l,0,2*pi*R);
>
> 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.
- - - - - - - - -
  Prabhakaran, isn't this essentially the same question you asked back in 18 Sep 2010 in the thread:

 http://www.mathworks.com/matlabcentral/newsreader/view_thread/288859 ?

  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.

  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.

Roger Stafford

Subject: help with double integration

From: prabhakaran m

Date: 29 Mar, 2012 03:45:26

Message: 5 of 5

"Roger Stafford" wrote in message <jl0jhj$30i$1@newscl01ah.mathworks.com>...
> "prabhakaran m" <prabha.gahon@gmail.com> wrote in message <jl0dnq$g19$1@newscl01ah.mathworks.com>...
> > need help to solve double integration. i have to calculate the fourier constant using the formula.
> >
> > 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.
> >
> > been puzzled here. the code below
> >
> > out = integrnd(x,y);
> >
> > A(m,n)= w(x,y)*cos(m*y/r)*cos(2*n*pi*x/l);
> >
> > result = dblquad(@integrnd,0,l,0,2*pi*R);
> >
> > 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.
> - - - - - - - - -
> Prabhakaran, isn't this essentially the same question you asked back in 18 Sep 2010 in the thread:
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/288859 ?
>
> 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.
>
> 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.
>
> Roger Stafford

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.

i have did the code

L=150;
R=(94.6/2+.5); %reference radius
x=0:10:150;
y=0:5:360;
theta=y*pi/180;
lentheta=length(theta);
result=[];
for ii=1:length(x)
  for jj=1:lentheta
    const=0.0;
for m=1:72
    for n=1:15
        I_term=w(ii,jj)*cos((m-1)*y(jj)/R)*cos(2*(n-1)*pi*x(ii)/L);
        const=const+I_term;
    end
end
result(ii,jj)=const;
end
end
i2 = [];
      for i=1:length(x)
  for j=1:lentheta
 I2(i,j) =(2/pi*L)* trapz(y,trapz(x,result));
  end
      end

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.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us