#*****************************************************************************80 # ## bvpexample_test tests bvpexample. # # Licensing: # # Copyright 2016 James P. Howard, II # # The computer code and data files on this web page are distributed under # https://opensource.org/licenses/BSD-2-Clause, the BSD-2-Clause license. # # Modified: # # 28 March 2020 # # Author: # # John Burkardt # cat ( date ( ), "\n" ) cat ( "\n" ) cat ( "bvpexample_test\n" ) cat ( " ", version$version.string, "\n" ) cat ( " bvpexample determines the additional initial value which\n" ) cat ( " converts a boundary value problem (BVP) into\n" ) cat ( " an initial value problem (IVP).\n" ) cat ( "\n" ) source ( "/home/burkardt/public_html/r_src/bisection/bisection.R" ) source ( "/home/burkardt/public_html/r_src/bvpexample/bvpexample.R" ) # # Initial exploration shows that the correct value is between 0 and 1. # for ( b in -2 : 2 ) { value = bvpexample ( b ) cat ( " f(", b, ") = ", value, "\n" ) } # # Call bisection to get the correct value. # bvp.b <- bisection ( bvpexample, 0.0, 1.0 ) cat ( "\n" ) cat ( " Correct initial value for y'(0) is ", bvp.b, "\n" ) # # Solve IVP with additional initial value. # odesystem <- function ( x, y ) { y1 <- y[2] y2 <- y[1]^2 - 2.0 return ( c ( y1 = y1, y2 = y2 ) ) } x0 <- 0.0 y0 <- c ( y1 = 1.0, y2 = bvp.b ) yn <- 1.0 n <- 1000 h <- 1.0 / n z <- eulersys ( odesystem, x0, y0, h, n ) print ( tail ( z, 1 ) ) # # Terminate. # cat ( "\n" ) cat ( "bvpexample_test\n" ) cat ( " Normal end of execution.\n" ) cat ( date ( ), "\n" ) quit ( )