help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using expm in C++


From: Ben Abbott
Subject: Re: Using expm in C++
Date: Mon, 06 Feb 2012 20:47:20 -0500

On Feb 6, 2012, at 8:24 PM, loisp wrote:

> On Tue, Feb 7, 2012 at 6:48 AM, bpabbott [via Octave] <[hidden email]> wrote:
> 
> On Feb 6, 2012, at 5:58 PM, loisp wrote: 
> 
> > Hello, 
> > 
> > I'm writing a C++ program and want to use the Octave function expm() 
> > (exponential of a matrix). Here is the relevant snippet from my code. 
> > 
> > hamiltonian = Matrix (N+1, N+1);    
> > for(int i = 0; i < N+1; i++) 
> > { 
> > for(int j = 0; j < N+1; j++) 
> > { 
> > if((i+1 == j) || (i == j+1)) 
> > hamiltonian (i, j) = -1; 
> > } 
> > } 
> > 
> > hamiltonian = hamiltonian.expm(); 
> > 
> > 
> > When I try to compile my program using mkoctfile I get the following error 
> > 
> > dmatrix.cpp: In function ‘int main()’: 
> > dmatrix.cpp:54: error: ‘class Matrix’ has no member named ‘expm’ 
> > 
> > I was wondering if the classes Matrix and ComplexMatrix provide that 
> > function and if they don't, do you have any work around to suggest? I am 
> > using MacOSX and have Octave installed though fink. 
> > 
> > Thanks in advance. 
> > 
> > Lois
> I may be wrong, but I don't think there is an expm is an on the c++ side. 
> However, there is an m-file version. You can call it via feval (although I've 
> never tried). 
> 
> http://www.gnu.org/software/octave/doc/interpreter/Calling-Octave-Functions-from-Oct_002dFiles.html
> 
> Ben 
> 
> The thing is I don't want to use an oct-file. I want my code to be in C++ and 
> to use Octave just for the expm() function. Is there any way I can achieve 
> that?

I'm unfamiliar with what you're asking, but I'll try to help.

If you only need to call expm and don't require anything else, I think you're 
better off recoding the expm function in c++.

        
http://hg.savannah.gnu.org/hgweb/octave/file/3e4350f09a55/scripts/linear-algebra/expm.m

If you really want to call Octave you can start with ...

        http://octave.sourceforge.net/doxygen/html/

There's a rather dated description for call Octave from c++ below.

        http://www.mathias-michel.de/download/howto-octave-c++.ps

Ben



reply via email to

[Prev in Thread] Current Thread [Next in Thread]