mvasamp4.cpp

Go to the documentation of this file.
00001 #include "cammva.h"
00002 #include "mvagph.h"
00003 #include <iostream.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <math.h>
00007 
00008 double f(double x,double y)
00009 {
00010 return (3*(1-x)*(1-x)*(exp(-x*x - (y+1)*(y+1)))
00011           -10*(x/5 - x*x*x - y*y*y*y*y)*(exp(-x*x - y*y))
00012           -(1/3.0)*(exp(-(x+1)*(x+1) - y*y)));
00013 
00014 };
00015 
00016 int main()
00017 {
00018 
00019         long N = 5;
00020         CAMdoubleVector B(N);
00021     CAMdoubleVector X(N);
00022 
00023     CAMmvaGraphics      Mgraphics;            // set up for mva graphics process
00024         CAMpostScriptDriver PSdriver("graph.ps"); // set up output driver
00025         Mgraphics.attachDriver(PSdriver);         // attach driver
00026 //
00027 // Initialize a test matrix and right hand side
00028 //
00029    long i;  long j;
00030    for(i=1; i<=N; i++)
00031    {
00032     B(i)=double(i);
00033     X(i)=double(i)*.25;
00034    }
00035    B(3) = -1;
00036 
00037 /*
00038 
00039    Mgraphics.plot(B);
00040    Mgraphics.frame();
00041    Mgraphics.plot(B,'G');
00042    Mgraphics.frame();
00043    Mgraphics.plot(B,'H',CAMgraphicsProcess::CURVE_AND_POINTS);
00044    Mgraphics.frame();
00045    Mgraphics.plot(X,B);
00046    Mgraphics.frame();
00047    Mgraphics.plot(X,B,'G');
00048    Mgraphics.frame();
00049    Mgraphics.plot(X,B,'H',CAMgraphicsProcess::CURVE_AND_POINTS);
00050    Mgraphics.frame();
00051 
00052 */
00053 
00054    long m; long n;
00055 
00056    m = 10;
00057    n = 40;
00058    CAMdoubleArray A(m,n);
00059    CAMdoubleArray XP(n);
00060    for(i= 1; i <= m; i++)
00061    {
00062    for(j = 1; j <=n; j++)
00063    {
00064      A(i,j) = cos(double(i)*3.14159*2.0*double(j-1)*(1.0)/double(n-1));
00065    }}
00066 
00067    for(j = 1; j <= n; j++)
00068    {
00069      XP(j) = double(j-1)/double(n-1);
00070    }
00071 
00072    /*
00073    Mgraphics.plot(A(1,_));
00074    Mgraphics.frame();
00075    Mgraphics.plot(A(2,_),CAMgraphicsProcess::CURVE_AND_POINTS);
00076    Mgraphics.frame();
00077    Mgraphics.plot(A(3,_),'+');
00078    Mgraphics.frame();
00079 
00080    Mgraphics.plot(XP,A(1,_));
00081    Mgraphics.frame();
00082    Mgraphics.plot(XP,A(2,_),CAMgraphicsProcess::CURVE_AND_POINTS);
00083    Mgraphics.frame();
00084    Mgraphics.plot(XP,A(3,_),'+');
00085    Mgraphics.frame();
00086    */
00087 
00088     m = 30;
00089     n = 30;
00090 
00091     CAMdoubleMatrix C(m,n);
00092 
00093     double a  = -3.0;                     // create data for contour plot
00094     double b  =  3.0;
00095     double c  = -3.0;
00096     double d =   3.0;
00097 
00098 
00099     double hx  = (b-a)/double(m-1);
00100     double hy  = (d-c)/double(n-1);
00101 
00102     for(i =1; i <= m; i++)
00103     {
00104     for(j =1; j <=n; j++)
00105     {
00106     C(i,j) = f(a + double(i-1)*hx, c + double(j-1)*hy);
00107     C(i,j) = 0.0;
00108     }}
00109 
00110     C(5,5)   = 1.0;
00111     C(n-3,n-3) = 1.0;
00112 
00113     Mgraphics.contour(C);
00114     Mgraphics.frame();
00115 /*
00116     Mgraphics.contour(C,10);
00117     Mgraphics.frame();
00118     Mgraphics.contour(C,.1);
00119     Mgraphics.frame();
00120     Mgraphics.contour(C,0.0,1.0);
00121     Mgraphics.frame();
00122     Mgraphics.contour(C,10,0.0,1.0);
00123     Mgraphics.frame();
00124     Mgraphics.contour(C,XP);
00125 */
00126     Mgraphics.surface(C);
00127     Mgraphics.frame();
00128 
00129 
00130    cout << " Program End : Hit Any Key to Terminate " << endl;
00131    getchar();
00132    return 0;
00133 }

Generated on Wed Aug 6 12:58:49 2003 for Open-Sessame Framework by doxygen1.3