From: Nikolaus Rath on
"Craig Dedo" <cdedo(a)wi.rr.com> writes:
>>>> 4. Are there any (free) modules that implement basic vector algebra,
>>>> like cross product, length etc in different coordinate systems?
>>>
>>> Don't know about this, nothing show up on google ?
>>
>> Not really. I only found some really basic module on
>> http://www.nag.co.uk/nagware/Examples.asp, but it only works in
>> cartesian coordinates.
>
> What features would you like to see in a vector algebra module?
> Please be specific. I may be interested in writing such a module and
> posting it on a web site.
>
> What kinds of coordinate systems are you interested in having it
> support? Obviously, Cartesian, cylindrical, and spherical should be
> included. Any others?

I am afraid I cannot (yet) come up with a detailed specification of
what features and coordinate systems I may need. At the moment I am
still trying around to get a feel for the language and was just
surprised that I had to write functions to convert from spherical to
cartesian coordinates, for cross product and length of a vector.

I suppose that for a proper vector algebra module it might be a good
start to take a look at the interface that e.g. Mathematica provides:

http://reference.wolfram.com/mathematica/VectorAnalysis/guide/VectorAnalysisPackage.html
http://reference.wolfram.com/mathematica/guide/OperationsOnVectors.html

Having a similar feature set available in Fortran would probably be
sufficient for a large number of problems.


Best,

-Nikolaus

--
Nikolaus(a)rath.org | College Ring 6, 28759 Bremen, Germany
Class of 2008 - Physics | Jacobs University Bremen

»My opinions may have changed, but not the fact that I am right.«
From: Arjen Markus on
On 4 apr, 11:31, Nikolaus Rath <Nikol...(a)rath.org> wrote:
> "Craig Dedo" <cd...(a)wi.rr.com> writes:
> >>>> 4. Are there any (free) modules that implement basic vector algebra,
> >>>>    like cross product, length etc in different coordinate systems?
>
> >>> Don't know about this, nothing show up on google ?
>
> >> Not really. I only found some really basic module on
> >>http://www.nag.co.uk/nagware/Examples.asp, but it only works in
> >> cartesian coordinates.
>
> > What features would you like to see in a vector algebra module?
> > Please be specific. I may be interested in writing such a module and
> > posting it on a web site.
>
> >    What kinds of coordinate systems are you interested in having it
> > support? Obviously, Cartesian, cylindrical, and spherical should be
> > included. Any others?
>
> I am afraid I cannot (yet) come up with a detailed specification of
> what features and coordinate systems I may need. At the moment I am
> still trying around to get a feel for the language and was just
> surprised that I had to write functions to convert from spherical to
> cartesian coordinates, for cross product and length of a vector.
>
> I suppose that for a proper vector algebra module it might be a good
> start to take a look at the interface that e.g. Mathematica provides:
>
> http://reference.wolfram.com/mathematica/VectorAnalysis/guide/VectorA...http://reference.wolfram.com/mathematica/guide/OperationsOnVectors.html
>
> Having a similar feature set available in Fortran would probably be
> sufficient for a large number of problems.
>
> Best,
>
>    -Nikolaus
>
> --
>  Nikol...(a)rath.org | College Ring 6, 28759 Bremen, Germany
>  Class of 2008 - Physics | Jacobs University Bremen
>
>  »My opinions may have changed, but not the fact that I am right.«- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

I have searched www.netlib.org for a bit:

2. linpack/sqrsl.f ( plus dependencies )
gams: D2a1, D9a1
for: applies the output of (linpack/sqrdc) to compute coordinate
transformations, projections, and least squares solutions
prec: single
Score: 99%

may be what you are after.


But what you call vector algebra, I would call coordinate
transformations. I found the above looking for "coordinate".
The search terms "vector algebra" bring up a lot of
implementations of linear algebra algorithms.

I am curious as to what kind of problems you are trying to
solve, as your terminology seems to be so different from
mine.

Many of the operations described in the Mathematica
documentation you refer to seem to be implementable
in just a few lines of code. For instance, the
angle between two vectors (in any dimension):

angle = acos( sum(v1*v2)/sqrt(sum(v1**2)*sum(v2**2)) )

To create an array of values from a function:

v = (/ (f(0.1*i), i=1,100) /)

(Simply dimension the array v to 100 and define a
function f like:
real function f(x)
real :: x
if ( x /=0 ) then
f = sin(x)/x
else
f = 1.0
endif
end function

Note that the abstraction/modus operandi is different.
That makes comparisons a trifle tough.

Regards,

Arjen
From: Nikolaus Rath on
Arjen Markus <arjen.markus(a)wldelft.nl> writes:
> I have searched www.netlib.org for a bit:
>
> 2. linpack/sqrsl.f ( plus dependencies )
> gams: D2a1, D9a1
> for: applies the output of (linpack/sqrdc) to compute coordinate
> transformations, projections, and least squares solutions
> prec: single
> Score: 99%
>
> may be what you are after.

I will take a look at it, thanks for the link!

> But what you call vector algebra, I would call coordinate
> transformations. I found the above looking for "coordinate".
> The search terms "vector algebra" bring up a lot of
> implementations of linear algebra algorithms.
>
> I am curious as to what kind of problems you are trying to
> solve, as your terminology seems to be so different from
> mine.

At the moment I am trying to simulate (rotating) x-ray diffraction of
crystal structures. The crystal lattice is best constructed in
cartesian coordinates, but for determining the interference pattern
and rotating the crystal it is much easier to switch to cylindrical or
spherical coordinates.

> Many of the operations described in the Mathematica documentation
> you refer to seem to be implementable in just a few lines of code.

Yes, that's true. I was just wondering if no one has yet collected all
these simple functions into a nice package. After all, even if they're
not difficult to write it's still a waste of time if everyone who needs
them has to write them again. But maybe I'm just to much used to CPAN
and Java where there is always a module for everything :-)


Best,


-Nikolaus

--
Nikolaus(a)rath.org | College Ring 6, 28759 Bremen, Germany
Class of 2008 - Physics | Jacobs University Bremen

»My opinions may have changed, but not the fact that I am right.«
From: Arjen Markus on
On 5 apr, 12:27, Nikolaus Rath <Nikol...(a)rath.org> wrote:
> Arjen Markus <arjen.mar...(a)wldelft.nl> writes:
> > I have searchedwww.netlib.orgfor a bit:
>
> > 2. linpack/sqrsl.f ( plus dependencies )
> > gams: D2a1, D9a1
> > for: applies the output of (linpack/sqrdc) to compute coordinate
> > transformations, projections, and least squares solutions
> > prec: single
> > Score: 99%
>
> > may be what you are after.
>
> I will take a look at it, thanks for the link!
>
> > But what you call vector algebra, I would call coordinate
> > transformations. I found the above looking for "coordinate".
> > The search terms "vector algebra" bring up a lot of
> > implementations of linear algebra algorithms.
>
> > I am curious as to what kind of problems you are trying to
> > solve, as your terminology seems to be so different from
> > mine.
>
> At the moment I am trying to simulate (rotating) x-ray diffraction of
> crystal structures. The crystal lattice is best constructed in
> cartesian coordinates, but for determining the interference pattern
> and rotating the crystal it is much easier to switch to cylindrical or
> spherical coordinates.
>
> > Many of the operations described in the Mathematica documentation
> > you refer to seem to be implementable in just a few lines of code.
>
> Yes, that's true. I was just wondering if no one has yet collected all
> these simple functions into a nice package. After all, even if they're
> not difficult to write it's still a waste of time if everyone who needs
> them has to write them again. But maybe I'm just to much used to CPAN
> and Java where there is always a module for everything :-)
>
> Best,
>
> -Nikolaus
>
> --
> Nikol...(a)rath.org | College Ring 6, 28759 Bremen, Germany
> Class of 2008 - Physics | Jacobs University Bremen
>
> »My opinions may have changed, but not the fact that I am right.«

That is partly cultural, I guess :). There are a lot of Fortran
modules,
packages, libraries, ... out there for a wide variety of problems.
Netlib
is a good source for such packages.

I am getting the picture now. I can imagine it is easier to specify
the computations
you need in sperical or cylindrical coordinates, but ultimately the
computations
themselves will have to be done using cartesian.

(My guess is that in the end working with cartesian coordinates
directly turns
out to be faster, but that is just a guess)

Just musing here:
You could define a derived type like this:

type coord3d
logical :: up_to_date ! Are the spherical coordinates up
to date?
real :: x, y, z
real :: rad, phi, theta
end type

(The type represents a point in 3D space in _both_ cartesian and
spherical coordinates,
so that switching back and forth is hidden and done only when needed).

Then define suitable operations:

interface operator(+)
module procedure add_3d_points
end interface

interface operator(.rot.)
module procedure rotate_3d_point
end interface


type(coord3d) function add_3d_points( p1, p2 )
type(coord3d) :: p1, p2

add_3d_points%x = p1%x + p2%x
add_3d_points%y = p1%x + p2%y
add_3d_points%z = p1%x + p2%z

add_3d_points%up_to_date = .false.
end function add_3d_points

type(coord3d) function rotate( p1, p2 )
type(coord3d) :: p1, p2
type(coord3d) :: sp1, sp2

sp1 = updated(p1) ! Make sure the spherical representation is
correct
sp2 = updated(p2)

rotate%phi = sp1%phi + sp2%phi
rotate%theta = sp1%theta + sp2%theta ! Assuming such rotation is
okay

rotate%up_to_date = .true.

end function rotate

etc...

Regards,

Arjen
From: Nikolaus Rath on
Arjen Markus <arjen.markus(a)wldelft.nl> writes:
> I am getting the picture now. I can imagine it is easier to specify
> the computations you need in sperical or cylindrical coordinates, but
> ultimately the computations themselves will have to be done using
> cartesian.
>
> (My guess is that in the end working with cartesian coordinates
> directly turns out to be faster, but that is just a guess)

I would be quite surprised if e.g. rotating the lattice around the
origin will really be faster in cartesian coordinates :-).

> Just musing here: You could define a derived type like this:
>
> type coord3d logical :: up_to_date ! Are the spherical coordinates
> up to date? real :: x, y, z real :: rad, phi, theta end type
>
> (The type represents a point in 3D space in _both_ cartesian and
> spherical coordinates, so that switching back and forth is hidden and
> done only when needed).

That is a very interesting idea.. Actually it seems to be much more
elegant to hide the entire coordinate representation than to
explicitly transform back and forth. I guess I'll really try doing it
this way - thanks for the idea.


Best,

-Nikolaus

--
Nikolaus(a)rath.org | College Ring 6, 28759 Bremen, Germany
Class of 2008 - Physics | Jacobs University Bremen

»My opinions may have changed, but not the fact that I am right.«
 | 
Pages: 1
Prev: ephemeris OT
Next: Fortran 77 parser