# include # include # include "fisher_exact.h" /******************************************************************************/ void f_exact ( double z, double *f, double *fz, double *fzz ) /******************************************************************************/ /* Purpose: f_exact() computes a function related to an exact solution of the KPP Fisher PDE. Discussion: ut = uxx + u * ( 1 - u ) Licensing: This code is distributed under the MIT license. Modified: 05 May 2024 Author: John Burkardt Reference: Mark Ablowitz, Anthony Zeppetella, Explicit solutions of Fisher's equation for a special wave speed, Bulletin of Mathematical Biology, Volume 41, pages 835-840, 1979. Daniel Arrigo, Analytical Techniques for Solving Nonlinear Partial Differential Equations, Morgan and Clayfoot, 2019, ISBN: 978 168 173 5351. Input: double Z: the evaluation point. Output: double *F, *FZ, *FZZ: the function and derivatives at Z. */ { double a; double bot; double k; fisher_parameters ( NULL, NULL, NULL, &a, NULL, &k ); bot = 1.0 + a * exp ( k * z ); *f = 1.0 / pow ( bot, 2 ); *fz = - 2.0 / pow ( bot, 3 ) * a * k * exp ( k * z ); *fzz = + 6.0 / pow ( bot, 4 ) * a * a * k * k * exp ( 2.0 * k * z ) - 2.0 / pow ( bot, 3 ) * a * k * k * exp ( k * z ); return; } /******************************************************************************/ double f_residual ( double f, double fz, double fzz ) /******************************************************************************/ /* Purpose: f_residual() computes a residual related to the KPP Fisher equation. Discussion: The KPP Fisher equation is ut = uxx + u * ( 1 - u ) For a particular value of c, and function f(z), the KPP Fisher equation admits a traveling wave solution of the form u(x,t) = f(x-ct) = f(z) where the function f(z) satisfies the ODE f'' + cf' + f - f^2 = 0 Licensing: This code is distributed under the MIT license. Modified: 05 May 2024 Author: John Burkardt Reference: Mark Ablowitz, Anthony Zeppetella, Explicit solutions of Fisher's equation for a special wave speed, Bulletin of Mathematical Biology, Volume 41, pages 835-840, 1979. Daniel Arrigo, Analytical Techniques for Solving Nonlinear Partial Differential Equations, Morgan and Clayfoot, 2019, ISBN: 978 168 173 5351. Input: double F, FZ, FZZ: the associated function and derivatives. Output: double R: the residual of the f(z) solution. */ { double c; double r; fisher_parameters ( NULL, NULL, NULL, NULL, &c, NULL ); r = fzz + c * fz + f - f * f; return r; } /******************************************************************************/ void fisher_exact ( double t, double x, double *u, double *ut, double *ux, double *uxx ) /******************************************************************************/ /* Purpose: fisher_exact() computes an exact solution of the KPP Fisher equation. Discussion: ut = uxx + u * ( 1 - u ) Licensing: This code is distributed under the MIT license. Modified: 04 May 2024 Author: John Burkardt Reference: Mark Ablowitz, Anthony Zeppetella, Explicit solutions of Fisher's equation for a special wave speed, Bulletin of Mathematical Biology, Volume 41, pages 835-840, 1979. Daniel Arrigo, Analytical Techniques for Solving Nonlinear Partial Differential Equations, Morgan and Clayfoot, 2019, ISBN: 978 168 173 5351. Input: double T, X: the time and position. Output: double *U, *UT, *UX, *UXX: the solution and derivatives at (T,X). */ { double a; double bot; double c; double k; double z; fisher_parameters ( NULL, NULL, NULL, &a, &c, &k ); z = x - c * t; bot = 1.0 + a * exp ( k * z ); *u = 1.0 / pow ( bot, 2 ); *ut = 2.0 * c / pow ( bot, 3 ) * a * k * exp ( k * z ); *ux = - 2.0 / pow ( bot, 3 ) * a * k * exp ( k * z ); *uxx = + 6.0 / pow ( bot, 4 ) * a * a * k * k * exp ( 2.0 * k * z ) - 2.0 / pow ( bot, 3 ) * a * k * k * exp ( k * z ); return; } /******************************************************************************/ void fisher_parameters ( double *a_in, double *c_in, double *k_in, double *a_out, double *c_out, double *k_out ) /******************************************************************************/ /* Purpose: fisher_parameters() returns parameters for the Fisher ODE. Discussion: If input values are specified, this resets the default parameters. Otherwise, the output will be the current defaults. Licensing: This code is distributed under the MIT license. Modified: 04 May 2024 Author: John Burkardt Input: double *a_in: a new value for A. double *c_in: a new value for C. double *k_in: a new value for K. Output: double *a_out: the default or new value for A. double *c_out: the default or new value for C. double *k_out: the default or new value for K. */ { static double a_default = 2.0; static double c_default = 5.0 / sqrt ( 6.0 ); static double k_default = 1.0 / sqrt ( 6.0 ); /* Update defaults if input was supplied. */ if ( a_in ) { a_default = *a_in; } if ( c_in ) { c_default = *c_in; } if ( k_in ) { k_default = *k_in; } /* Return values. */ if ( a_out ) { *a_out = a_default; } if ( c_out ) { *c_out = c_default; } if ( k_out ) { *k_out = k_default; } return; } /******************************************************************************/ double fisher_residual ( double t, double x ) /******************************************************************************/ /* Purpose: fisher_residual() computes the residual of the KPP Fisher equation. Discussion: ut = uxx + u * ( 1 - u ) Licensing: This code is distributed under the MIT license. Modified: 05 May 2024 Author: John Burkardt Reference: Mark Ablowitz, Anthony Zeppetella, Explicit solutions of Fisher's equation for a special wave speed, Bulletin of Mathematical Biology, Volume 41, pages 835-840, 1979. Daniel Arrigo, Analytical Techniques for Solving Nonlinear Partial Differential Equations, Morgan and Clayfoot, 2019, ISBN: 978 168 173 5351. Input: double T, X: the time and position. Output: double R: the residual at that time and position. */ { double r; double u; double ut; double ux; double uxx; fisher_exact ( t, x, &u, &ut, &ux, &uxx ); r = ut - uxx - u * ( 1.0 - u ); return r; }