How to start using the GNU Octave libraries for Visual C++?
I've read carefully the site but couldn't find any info how to start working with it in details.
Especially I'm interested in this example:
http://www.gnu.org/software/octave/doc/interpreter/Nonlinear-Equations.html
Starting from words: "Here is a complete example..." I wanna see this in C++ code :)

So, if someone had experience working with it, please write in few words: How to start, which libraries to download, where to install and other...
(MS Visual C++ 2008)
Thank you!

Hi

I don't have octave experience, I am using matlab. But I know there is a octave library for c/c++. Maybe this small tutorial helps a little. There is a further advanced tutorial.

-- tesu

I couldn't get this to completely work right now, but here is what I came up with when I tried to do it a while back. It certainly needs some cleaning!

// need to
// export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include/octave-3.2.4
// export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/octave-3.2.4
#include <octave/octave.h>
#include <octave/oct.h>
#include <octave/parse.h>

#include <iostream>

void Test1();
void Test2();
void OneParam();
void TestRand();
void Prob();
void SetDir();

int main(int argc, char **argv)
{
  if (octave_main (argc, argv, 1))
  {
    TestRand();
    OneParam();
    Test2();

    SetDir();
    Prob();
  }
  else
  {
    error ("Octave interpreter initialization failed");
  }

  return 0;
}


void Test2()
{
	octave_value_list f_arg, f_ret;

	f_arg(0) = octave_value(2.5);
	f_arg(1) = octave_value(2.6);
	f_ret = feval("min",f_arg);

	Matrix unis (f_ret(0).matrix_value ());
	std::cout << unis;
}


void OneParam()
{
	octave_value_list f_arg, f_ret;
	f_arg(0) = octave_value(-1);
	f_ret = feval("acos", f_arg);
	Matrix unis (f_ret(0).matrix_value ());
	std::cout << unis;
}


void TestRand()
{
	ColumnVector NumRands (2);
	//NumRands(0) = 9000;
	NumRands(0) = 10;
	NumRands(1) = 1;
	
	octave_value_list f_arg;
	f_arg(0) = octave_value (NumRands);
	
	octave_value_list f_ret = feval ("rand", f_arg, 1);
	
	if (f_ret.length () > 0)
	{
		Matrix unis (f_ret(0).matrix_value ());
	
		std::cout << __FILE__ << ":" << __LINE__ << ":" << unis;
	}
}

void Prob()
{
	octave_value_list f_arg, f_ret;

	double c = .01;
	double m = .5;	
	for(double d = 0; d < 5; d++)
	{
		for(int l = 0; l < 5; l++)
		{
		
			f_arg(0) = octave_value(d);
			f_arg(1) = octave_value(l);
			f_arg(2) = octave_value(c);
			f_arg(3) = octave_value(m);
			f_ret = feval("ProbNumeric", f_arg);
			//Matrix unis (f_ret(0).matrix_value ());
			//std::cout << unis;
		
			double P = f_ret(0).double_value();
		
			std::cout << "P: " << P << std::endl;
		}
	}
}

void SetDir()
{
	octave_value_list f_arg, f_ret;
	f_arg(0) = "/media/portable/Examples/c++/src/Octave";
	
	feval("cd", f_arg);
}

Let me know if you have any questions - we'll get it to work and clean up this example and put it somewhere for the "next guy".

Dave

Thank you very much Dave! Sorry, I just recognized your answer (I didn't get any notification on my mail box).
I'm going to try and realize this example and post here my feedback..
Thanks again!

Hello Dave!
I couldn't rich the point when I can use the C++ code ("octave.h" library is missing and other...).
So, there are number of questions:
1) Do I need to install the full "GNU Octave" on my computer, before trying it on C++?
2) How can I connect the Octave to C++? (Which libraries I have to export and where? My C++ path: "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\...").

So before using the C++ code could you please be so kind to explain in details the mentioned up things?

Thanks again!

Yes, you definitely need to install octave, as well as octave_devel. I just do a:

sudo yum install octave*

It won't be so easy on Windows :)

For some reason I always have to change in octave.h

extern OCTINTERP_API int octave_main (int argc, char **argv, int embedded);

to

extern int octave_main (int argc, char **argv, int embedded);

You then have to link your program to 'octave' and 'octinterp'. My CMakeLists.txt file looks like this:

cmake_minimum_required(VERSION 2.6)

PROJECT(OctaveTest)

INCLUDE_DIRECTORIES(/usr/include/ 
/usr/local/include/ 
/usr/include/octave-3.2.4/
)

LINK_DIRECTORIES(/usr/lib /usr/local/lib
#/usr/lib/octave-3.0.2/
#/usr/lib/octave-3.0.1/
/usr/lib/octave-3.2.4/
)

ADD_EXECUTABLE(OctaveTest OctaveTest.cpp)

TARGET_LINK_LIBRARIES(OctaveTest  
octave octinterp
)

Good luck!

Dave

Hello. Have you got your problem solved? I am doing the same thing recently, and I don't know how to use the Octave libraries for Visual C++. So I am wondering if you could help me.

Thank you~

Manlin

Hello. Have you got your problem solved? I am doing the same thing recently, and I don't know how to use the Octave libraries for Visual C++. So I am wondering if you could help me.

Thank you~

Manlin

Oh, I spent some time to find the way to solve this, but I don’t have too much experience with this type of activity.
It was much easier for me to write my own procedure on Visual C++ which can solve the system of nonlinear equations. So now I’m using it. It works properly at 95% cases approximately (depending on the border conditions).
Anyway, the post is not solved. I would be happy to see step by step how to use the Octave procedures or connect to Visual C++ any other procedure which can solve the system of nonlinear equations.
Thank you!

Yeah, it will be really good if we can connect Octave to Visual C++. Let's hope someday we can do this.
Thank you for your time!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.