Actual source code: test9.c

slepc-3.17.0 2022-03-31
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-, 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: {
 17:   FN             fn;
 18:   PetscScalar    x,y,yp,tau,eta;
 19:   char           strx[50],str[50];

 21:   SlepcInitialize(&argc,&argv,(char*)0,help);
 22:   FNCreate(PETSC_COMM_WORLD,&fn);

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

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

 51:   FNDestroy(&fn);
 52:   SlepcFinalize();
 53:   return 0;
 54: }

 56: /*TEST

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

 63: TEST*/