00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <windows.h>
00011 #include <stdlib.h>
00012 #include <stdio.h>
00013 #include <string.h>
00014 #include "engine.h"
00015
00016 #define BUFSIZE 256
00017
00018 static double Areal[6] = { 1, 2, 3, 4, 5, 6 };
00019
00020 int PASCAL WinMain (HINSTANCE hInstance,
00021 HINSTANCE hPrevInstance,
00022 LPSTR lpszCmdLine,
00023 int nCmdShow)
00024
00025 {
00026 Engine *ep;
00027 mxArray *T = NULL, *a = NULL, *d = NULL;
00028 char buffer[BUFSIZE+1];
00029 double *Dreal, *Dimag;
00030 double time[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
00031
00032
00033
00034
00035 if (!(ep = engOpen(NULL))) {
00036 MessageBox ((HWND)NULL, (LPSTR)"Can't start MATLAB engine",
00037 (LPSTR) "Engwindemo.c", MB_OK);
00038 exit(-1);
00039 }
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 T = mxCreateDoubleMatrix(1, 10, mxREAL);
00052 memcpy((char *) mxGetPr(T), (char *) time, 10*sizeof(double));
00053
00054
00055
00056
00057 engPutVariable(ep, "T", T);
00058
00059
00060
00061
00062
00063 engEvalString(ep, "D = .5.*(-9.8).*T.^2;");
00064
00065
00066
00067
00068 engEvalString(ep, "plot(T,D);");
00069 engEvalString(ep, "title('Position vs. Time for a falling object');");
00070 engEvalString(ep, "xlabel('Time (seconds)');");
00071 engEvalString(ep, "ylabel('Position (meters)');");
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 a = mxCreateDoubleMatrix(3, 2, mxREAL);
00082 memcpy((char *) mxGetPr(a), (char *) Areal, 6*sizeof(double));
00083 engPutVariable(ep, "A", a);
00084
00085
00086
00087
00088 engEvalString(ep, "d = eig(A*A')");
00089
00090
00091
00092
00093
00094 buffer[BUFSIZE] = '\0';
00095 engOutputBuffer(ep, buffer, BUFSIZE);
00096
00097
00098
00099
00100
00101 engEvalString(ep, "whos");
00102 MessageBox ((HWND)NULL, (LPSTR)buffer, (LPSTR) "MATLAB - whos", MB_OK);
00103
00104
00105
00106
00107 d = engGetVariable(ep, "d");
00108 engClose(ep);
00109
00110 if (d == NULL) {
00111 MessageBox ((HWND)NULL, (LPSTR)"Get Array Failed", (LPSTR)"Engwindemo.c", MB_OK);
00112 }
00113 else {
00114 Dreal = mxGetPr(d);
00115 Dimag = mxGetPi(d);
00116 if (Dimag)
00117 sprintf(buffer,"Eigenval 2: %g+%gi",Dreal[1],Dimag[1]);
00118 else
00119 sprintf(buffer,"Eigenval 2: %g",Dreal[1]);
00120 MessageBox ((HWND)NULL, (LPSTR)buffer, (LPSTR)"Engwindemo.c", MB_OK);
00121 mxDestroyArray(d);
00122 }
00123
00124
00125
00126
00127 mxDestroyArray(T);
00128 mxDestroyArray(a);
00129
00130 return(0);
00131 }