"Arseny Kubryakov" <arskubr@gmail.com> wrote in message <j85m7o$g1a$1@newscl01ah.mathworks.com>...
>
> > Once you know the value of G at some particular point, you can find its value at any other point by taking the line integral of the given gradient along any path between the two points. If G is truly a gradient, meaning that its curl must be identically zero, the line integral value will be independent of the path taken.
> >
> > This means you should be able to construct a twodimensional G by first taking a cumulative integral of the gradient along some straight line containing the particular point, and then for each discrete point evaluated along this line, take a cumulative integral along an orthogonal line. This would give you the value of G at a 2D mesh of points. (Of course if you are working in three dimensions it will require one additional level of integration along the third dimension.)
> >
> > Matlab's 'cumtrapz' is such a cumulative integration function, or for higher order integration there are cumulative integration routines available in FEX. For example I have one that does third order approximation at:
> >
>
> > Roger Stafford
>
> Dear Roger! Thanks a lot You for your answer.
> But I am not sure that I understood it clearly. What exactly I should put into cmtrapz? May be I should explain my problem more detail:
> So, I have FX and FY, that can be computed from F as
> [FX,FY] = gradient(F)
Take a fix point in 2D, X0, another point (X), and any curve C(x) that links X0 to X, then
F(X) = F(X0) + integral_curve dot (G(x),t(x)) dl(x)
t(x) is a tangential vector to the curve C(x). G(x) is the gradient.
If you choose the curve as going eastwest then northsouth, you'll see it a sum of two integrals that can be calculated by two trapz as Roger indicates.
This assume that G(x) is irrotational vector field (any gradient field is irrotational, if it does not have any significant numerical error).
A more reliable way is writing the gradient equation in PDE form and solve it using (sparse) matrix.
Bruno
