Actual source code: test9.c

slepc-3.11.2 2019-07-30
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-2019, Universitat Politecnica de Valencia, Spain

  6:    This file is part of SLEPc.
  7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
  8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9: */

 11: static char help[] = "Test logarithm function.\n\n";

 13: #include <slepcfn.h>

 15: int main(int argc,char **argv)
 16: {
 18:   FN             fn;
 19:   PetscScalar    x,y,yp,tau,eta;
 20:   char           strx[50],str[50];

 22:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 23:   FNCreate(PETSC_COMM_WORLD,&fn);

 25:   /* plain logarithm log(x) */
 26:   FNSetType(fn,FNLOG);
 27:   FNView(fn,NULL);
 28:   x = 2.2;
 29:   SlepcSNPrintfScalar(strx,50,x,PETSC_FALSE);
 30:   FNEvaluateFunction(fn,x,&y);
 31:   FNEvaluateDerivative(fn,x,&yp);
 32:   SlepcSNPrintfScalar(str,50,y,PETSC_FALSE);
 33:   PetscPrintf(PETSC_COMM_WORLD,"  f(%s)=%s\n",strx,str);
 34:   SlepcSNPrintfScalar(str,50,yp,PETSC_FALSE);
 35:   PetscPrintf(PETSC_COMM_WORLD,"  f'(%s)=%s\n",strx,str);

 37:   /* logarithm with scaling factors eta*log(tau*x) */
 38:   FNSetType(fn,FNLOG);
 39:   tau = 0.2;
 40:   eta = 1.3;
 41:   FNSetScale(fn,tau,eta);
 42:   FNView(fn,NULL);
 43:   x = 2.2;
 44:   SlepcSNPrintfScalar(strx,50,x,PETSC_FALSE);
 45:   FNEvaluateFunction(fn,x,&y);
 46:   FNEvaluateDerivative(fn,x,&yp);
 47:   SlepcSNPrintfScalar(str,50,y,PETSC_FALSE);
 48:   PetscPrintf(PETSC_COMM_WORLD,"  f(%s)=%s\n",strx,str);
 49:   SlepcSNPrintfScalar(str,50,yp,PETSC_FALSE);
 50:   PetscPrintf(PETSC_COMM_WORLD,"  f'(%s)=%s\n",strx,str);

 52:   FNDestroy(&fn);
 53:   SlepcFinalize();
 54:   return ierr;
 55: }

 57: /*TEST

 59:    test:
 60:       suffix: 1
 61:       nsize: 1
 62:       filter: grep -v "computing matrix functions"

 64: TEST*/