[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Can the octave library be used for non-octave binaries?
From: |
Stephen W. Juranich |
Subject: |
Re: Can the octave library be used for non-octave binaries? |
Date: |
Wed, 24 Oct 2001 14:23:52 -0700 |
Okay, here's a working, extremely trivial stand-alone program that uses the
(hopefully) minimum number of outside libraries. I've been able to get the
SVD stuff working, but I couldn't make the DET class work right yet. Right
now, I have to move on to preparing a proposal defense, so that will have to
wait. :)
Anyway, the first snip is the actual C++ code, and the second is the (GNU)
Makefile that made it all happen. I don't think there's anything GNU specific
in the Makefile, but I could be wrong. Of course, the -I and -L arguments
will vary according to your system's setup, but you should be able to get the
gist of it all with the following.
Thanks, Doug!
--------------------------------------------------------------------------
Stephen W. Juranich address@hidden
Electrical Engineering http://students.washington.edu/sjuranic
University of Washington http://ssli.ee.washington.edu/ssli
----------------------- octave_matrix.cc ------------------------------------
// OCTAVE_MATRIX.CC
// This is my first crack at using matrices from the octave library.
// I hope to God that this works, because I really don't want to have
// to implement a matrix class as well.
#include <octave/oct.h> /* This should be all that I have to
include. */
#include <octave/dbleSVD.h>
int eck_test(void) {
// This is code that was mailed by Doug Eck from the octave mailing
// list.
int sz = 20;
Matrix m(sz, sz);
for(int r = 0; r < sz; r++) {
for(int c = 0; c < sz; c++) {
m(r,c) = (double) r * c;
}
}
cout << "Hello world!" << endl;
cout << m;
return 0;
}
int vector_test(void) {
RowVector v(5, 3.2);
ColumnVector w(5, 0.8);
double inner = v * w;
Matrix outer = w * v;
cout << "The inner product is: " << inner << endl;
cout << "The outer product is:" << endl;
cout << outer;
Matrix M(2,2);
for(int r = 0; r < 2; r++) {
for(int c = 0; c < 2; c++) {
M(r,c) = (double) (2 * r) + c + 1;
}
}
cout << M;
// DET det(M.determinant());
// Matrix iM;
// if(det)
// iM = M.inverse();
// cout << "The determinant of M is " << det << endl;
// if(det) {
// cout << "The inverse of M is:"
// cout << iM;
// }
SVD USV(M);
cout << "The singular value matrix is: " << endl <<
USV.singular_values() << endl;
return 0;
}
int main(void) {
// eck_test();
vector_test();
return 0;
}
---------------------------------- Makefile ---------------------------------
CFLAGS := -I/g/ssli/research/SunOS/include
LIBDIRS := -L/g/ssli/research/SunOS/lib/octave
LIBS := -loctave -lcruft -lg2c
# ^^^^^ This is necessary!!
CCFLAGS := $(CCFLAGS) $(CFLAGS)
CC := /g/scs/sw/bin/g++
octave_test: octave_test.o
$(CC) $< -o $@ $(LIBDIRS) $(LIBS)
clean:
-rm *.o *~
%.o : %.cc
@echo Compiling address@hidden
$(CC) -c $(CCFLAGS) $< -o $@
%.o : %.cc %.h
@echo Compiling address@hidden
$(CC) -c $(CCFLAGS) $< -o $@
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------