Date: 2024-09-25T09:34:48+00:00

Actual source code: test9.c
slepc-3.21.2 2024-09-25
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:   PetscFunctionBeginUser;
     22:   PetscCall(SlepcInitialize(&argc,&argv,(char*)0,help));
     23:   PetscCall(FNCreate(PETSC_COMM_WORLD,&fn));

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

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

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

     57: /*TEST

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

     64: TEST*/