From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Integrating f(x,y) on a certain line in XY plane
Date: Mon, 9 May 2011 05:06:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <iq7sns$1j5$>
References: <iq5tkg$j6e$> <iq5vo1$nch$> <iq6390$17d$> <iq6t1h$ocu$> <iq704t$1av$> <iq740k$9e4$> <iq7900$jj3$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1304917564 1637 (9 May 2011 05:06:04 GMT)
NNTP-Posting-Date: Mon, 9 May 2011 05:06:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:725795

"Mohamed Nasr" wrote in message <iq7900$jj3$>...
> How will you tell matlab the coordinates of the line l in order to integrate on it?
> Note that in this 2D problem I cannot just consider the length of the line of integration regardless of its position in space due to physics of problem. It is getting charge distribution on a contour which I already know its voltage so position of one part of body w.r.t. other part can totally change charge distribution...
- - - - - - - - - -
  Mohamed, you wrote this:

as XM and YM are known values while X,Y are the variables to be integrated on the line connecting 2 points (X1,Y1) and (X2,Y2)."  I assumed when I read that that the quantities XM and YM where values held constant throughout the integration line between (X1,Y1) and (X2,Y2).  If that is so, then as I said, there is a simple formula for that integral with no numerical integration required.

  However your statement "It is getting charge distribution on a contour" would appear to imply that XM and YM vary as you travel along the length of the line.  If that is the case, then it is a different problem and your integral would probably require numerical integration.

  It would be helpful at this point if you could make an unambiguous statement as to whether the XM and YM in your expression do or do not vary along the length of the path.  Also you should make clear that when you say "line" you mean a straight line, as contrasted with some curved path along a contour.  Both John's and my comments have been based on the assumption that you meant a straight line.  With a curved path it is a different world again.  It is understood in mathematics that the word 'line' always refers to a straight line, not a curved path.

  Assuming that they do vary as functions of position (x,y) and that you are traveling along a straight line, call them XM(x,y) and YM(x,y).  It is up to you to define these functions.  Then your integrand could be expressed as a function of s as follows:

 f(x(s),y(s)) = 1/2*log((x(s)-XM(x(s),y(s)))^2+(y(s)-YM(x(s),y(s)))^2)

where s is the distance measured along the straight line from (x1,y1) to (x2,y2).  The variables x and y depend on s according to the equations:

 x(s) = x1+a*s
 y(s) = y1+b*s


 a = (x2-x1)/d
 b = (y2-y1)/d
 d = sqrt((x2-x1)^2+(y2-y1)^2)

The integral you would then evaluate would be the integral of f(x(s),y(s)) taken with respect to distance s from s = 0 to s = d.

  If you are able to express XM(x,y) and YM(x,y) as valid matlab functions, then you could use quadrature functions such as quad or the like.  Otherwise, you would probably have to use 'trapz' for your numerical integration making use of some sort of discrete values for XM(x,y) and YM(x,y) (probably requiring some interpolation.)

  I hope all this makes sense to you.  I can do no better until you make very clear these ambiguities which I have mentioned above.

Roger Stafford