±`·L¤Àµ{¨D¸Ñ¡G¨B´T½Õ¾A±±¨îªº¶©¥¨¡X®w¶ðªk

 

¥iÅܤƪº¨B´T±±¨î¤§¤èªkºK­n

R-K ¤èªk¦b«e¤@­Ó³æ¤¸¤v¸g¤¶²Ð¹L¡A¨Ï¥Î·L¨B°Æµ{¦¡ rk4¡A¥¦·f°t rkdumb ³o­Ó¨C¤@­Ó·L¨B³£µ¥¶¡¹jªº¿n¤ÀÅX°Ê¾¹°Æµ{¦¡¡A´£¨Ñ¤Fª½±µ¦³®Äªº¨D¸Ñ¤è®×¡C

µM¦Ó¡A§Ú­Ì¤£Ãø·Q¹³¡A¦b±À¶i·L¨Bªº¨D¸Ñ¹Lµ{¤¤¡A¦U¶¥±×²v¨ç¼ÆªºÅܤƧֺC¦b¦U³B¤£ºÉ¬Û¦P¡A­Y¥H¦P¼Ëªº¨B´T¼e«×¨Ó±À¶i¡A«h¥i¯à¦³¨Ç¦a¤èºë½T«×¤£¨¬¡A¦Ó¦³¨Ç¦a¤è«h¤S²Ó¤À¤F¤Ó¦h¤£¥²­nªº°Ï¶¡¡A³o¨Ã¤£¬O®Ä²v³Ì°ªªº¤èªk¡C

¦pªG¿n¤ÀÅX°Ê¾¹°Æµ{¦¡¯àºÊ±±¨C¤@¨Bªº»~®t¡A¨Ã§@§´µ½ªº½Õ¾A¥H²Å¦X¨Ï¥ÎªÌ©Ò³]©wªº³]®t®e§Ô«×¡A«h¨ç¼ÆÅܤư_¥ñ¶V¤jªº¦a¤è¤~·|¥Î¨ì¶V¤p¨B´Tªº¡A¦³§U©ó¾ãÅé®Ä²vªº¤j´T´£ª@¡C³oºØ¤èªk¡A§Ú­ÌºÙ¤§¬°¨ã¨B´T½Õ¾A±±¨î¥\¯à¡]Adapted Step-size Control¡^ªº¤èªk¡C

¦b¥»¸`¡]NR 16.2) ¤¤½Ò¥»¤¶²Ð¦³»~®t±±¨îªº R-K ºtºâªk¡A¨Ã±ÀÂˬ°¥i¥Î©ó¦hºØ¤£¦PÃþ«¬±`·L¤À¤èµ{¦¡ªº¨D¸Ñªºªx¥Î¤u¨ã¡A¤×¨ä¬O¦b¤U¤@³¹¤¶²Ð¨âÂIÃä¬É­È°ÝÃD¡]NR 17.1¡B17.2¡^®É¤]·|¥Î¨ì¡A¦]¦¹§ä§Ú­Ì¤´­n»{ÃѨým²ß¨Ï¥Î³o­Ó¤èªk¡C

¨B´T½Õ¾Aªº°ò¥»Æ[©À¡A¦b©ó (1) ¯àºÊ±±»~®t¤j¤p (2) ¯à¨Ì»~®t¤j¤p½Õ¾ã¥X³Ì¾A¤Áªº¨B´T¡C

¦b¦¹ºtºâªk³]­pªº§Þ¥©°ª©ó°ò¥»ªº¼Æ¾ÇÆ[©À¡A¥»³æ¤¸§Ú¤]´N¤£­n¨D¤j®a¤@©w­n¼ô±x¨ä¤½¦¡±À¾É¤Wªº²Ó¸`¡A¶È¹ªÀy¦³¿³½ì¤§¦P¾Ç¦Û¦æ²`¤J¾\Ū¤U¦CÁ¿¸q¤Î­ì½Ò¤å¡C¦Ü©ó°Æµ{¦¡ªº¨Ï¥Î§Ú­Ì«h­n¨D¦P¾Ç­Ì³£ÁÙ¬O­n·|¡A¦]¦¹·|§@¸Ô²Óªº¤ÀªR»¡©ú¡C

¤£ºÞ¦p¦ó¡A¦b¦¹±Nºtºâªk³]­pªº­nÂI¡]±µ½Ò¤å¶¶§Ç¡^¸Ô­z¦p¤U¡G

(1) »~®t¦ôºâªº¤è¦¡

¤@ºØ±`¥Îªº¤èªk¡]¦ý¤£¬O¥»¸`°Æµ{¦¡©Ò±Ä¥Îªº¡^¡A¬O¦b­ìºtºâªkªº±À¾É¦¡¤¤§â¨B¼Æ¥[­¿¡]§Y¨B´T´î¥b¡^¡A¦Ó¨B¼Æ¥[­¿±¡ªp¤U¨«¨â¨Bµ¥®Ä©ó­ìºtºâªk¨«¤@¨B¡A¦ý¥¦­Ìªº®õ°Ç®i¶}§Î¦¡¨Ã¤£¥þ¦P¦]¦¹¦³©Ò®t²§¡A

§Q¥Î¦¹¤@®t²§¥i¦¸±o¥X­ìºtºâªk¤º¦bªº»~®t¦æ¬°¡]¥H¥¿¤ñ©ó¨B´T¤j¤pªº´X¦¸¤è³oºØ¤è¦¡§e²{¡^¡C

½Ò¤å¤½¦¡ (16.2.1) ¦Ü (16.2.3) ´N¬O¦b»¡©ú±À¾É²Ó¸`¡A¬OÆZ´¶¹Mªº§@ªk¡C¦³¥[¨«¨B¼Æ­¿¼W¤§¤èªkªº¨ç¼Æ¨D­È°Ê§@ùØ¡A¦³¨Ç¬O¥ý«e¨«¤@¨B´N°µ¹Lªº¡A¨£¹Ï

¦]¦¹Á`¦@¬O 11 ¦¸¡A¤ñ°_¤@¶}©l´N¥Î¤@¥b¨B´T¤j¤pªº 8 ¦¸¡]¦b¬Û¦P¥ß¨¬ÂI¤W¨Ó¤ñ¡A­n¨â¦¸¥b¨B¤~¬Û·í©ó±À¨B¤@¨Bªº½d³ò¡^¡A¥N»ù¬O 1.375 ­¿¡A¤£ºâ¤Ó¦h¡A¦Ó©Ò´«±oªº¬O¦ô­pªº»~®t¸ê°T¡A¨Æ¹ê¤W·|Àò±o¬Û·í¤jªº®Ä¯à´£ª@¡C

¥H¤Wªº§@ªk¡A¬Ý°_¨ÓÁöµM¥i¥HÄ~Äò¦A¶i¤@¨B²Õ¦X¥X§ó°ª¶¥ªººtºâªk¡A

¦ý¤w¦³¬Û·í°ª¶¥¤èªk¥i¥Îªº±¡ªp¤U¡A³o¥¼¥²¬O¸Ñ¨M°ÝÃD©Ò³Ì»Ý­nªº¡]§ó°ª¶¥¤£¤@©w¥Nªí§óºë±K¡^¡A³o¼Ë§@¨Ã¤£¯àµ¹¥X§Ú­Ì³Ì»Ý­nªº¡A´N¬O»~®t¦ô­p¡C

½Ò¥»ùØ­±¤]¶¶«K´£¨ì¬°¤°»ò 4 ¶¥ R-K ¤èªk¬O³Ì³Q¼s¬°±Ä¥Îªº¡A§ó°ª¶¥ªº R-K ¤èªk¤]¦³³Q±À¾É¥X¨Ó¡A¤j®aµo²{¥u­n¬O¶¥¼Æ M ¤j©ó 4 ªº¡A³£»Ý­n¦h©ó M ¦¸ªº±×²v¨ç¼Æ¨D­È¡]¦ý¤£·|¦h©ó M+2 ¦¸¡^¡A¦]¦¹¡A¹ï©ó¶È»Ý¨D­È 4 ¦¸ªº 4 ¶¥ R-K ¤èªk¦ü¥G¬O¤ñ¨ä¥L¶¥¼Æ§ó¦Eºâ¡]½Ò¤å§@ªÌ¦A¦¸´£¿ô¤j®a¶V°ª¶¥¥¼¥²¶Vºë·Ç¡^¡C

¦b¥»¸`°Æµ{¦¡©Ò­n¥Î¨ìªº¡A«h¬O°w¹ï R-K¡A¦³¥t¤@ºØ¥i¦æªº¤è¦¡¡A¥¦¬O±q¤@­Ó»Ý§@¤»¦¸¨ç¼Æ¨D­Èªº¤­¶¥ªº R-K ¤èªk¥Xµo¡A

¥¦¦³¥t¤@¦¡¯S®í²Õ¦X¥i§Î¦¨¥|¶¥¤èªk¡A

³o¨âªÌªº®t²§¤]´N´£¨Ñ¤F»~®tªº©w¸q¡]´«¥y¸Ü»¡¡A´N¬Oªí¥Ü¥X¨B´T¤j¤p¡]x ªº»~®t¡^»P¨ç¼Æ»~®t¡]y ªº»~®t¡^¶¡ªºÃö«Y¡A¦p¤U¦¡¡G

³o¨ä¤¤ªº«Y¼Æ³£¤w¸g¬O¦³¤H±À¾É§¹¦¨ªº½T©w­È¡A¦p¤Uªí

 

(2) ½Õ¾ã¨B´Tªºµ¦²¤

«e­±¤w´£¨ì¡A»~®t¦ô­p«Ü­«­nªº¤@ÂI¬O¡A«Ý¨D¸Ñ¨ç¼Æ y ªº»~®t D »P¨B´T¤j¤p h ªºÃö«Y¬O«ç»ò¼Ë¡H

«e­±ªº±À¾É¬Ý±o¥X D ¬O»P h5 ¦¨¥¿¤ñ¡A¦ý³s±µ¨âªÌªº¤ñ¨Ò±`¼Æ§Ú­Ì·íµM¬O¤£ª¾¹D¡C ²{¦bÅý§Ú­Ì·Q¹³¨Ï¥Î¤F h1 ¦Ó¾É­P¤F»~®t¥¿¤ñ©ó D1¡A ¦Ó§Ú­Ì­ì¥»­Y¬O¨ú¤F h0 ¦Ó³y¦¨¤F D0¡A«h h1 »P h0 ªºÃö«Y´N·|¬O

§Ú­Ì²ßºD¤W±N D0·í§@¬O¨Ï¥ÎªÌ¹w¥ý³]©w¦nªº»~®t®e§Ô«×¡A«h¤W­±³o­ÓÃö«Y¦¡¦³¨âºØ¥Îªk¡G¨ä¤@¡B·í§Ú­Ì²{¦b³o¤@¨B¥Îªº h1 Àò±oªº D1 ¤ñ D0 ¤j¡A§Ú­Ìª¾¹D§â¤ñ¨Ò¶}¤­¦¸¤è­¼¤W­ì¨Ó¨Ï¥Îªº¨B´T¨Ó­«¶]¡F¨ä¤G¡B¦pªG³o¤@¨B h1 ¦ô¥X¨Óªº D1 ¤ñ D0 ¤p¡A«h¤W¦¡§i¶D§Ú­Ì¤U¤@¨Bªº h2 ¤j·§¥i¥H©ñ¤j¨ì¦h¤j¤´¬O¦w¥þªº¡C

±µ¤U¨Óªº°ÝÃD¡A¬O D0 ¥»¨­À³¸Ó«ç»ò³]©w¡H¡]½Ðª`·N¡A D0 ¬O¤@­Ó¦V¶q¡Aµø°ÝÃDªº»Ý­n¡A¥¦¹ï©ó¨C¤@­Ó yi ³£¥i¥H¦³¿W¥ßªº­Èªº¡C¡^ §Ú­Ì«e­±»¡­n§â¥¦·í§@¬O»~®t®e§Ô­È¡Aµ¹¤@­Óµ´¹ï¼Æ·íµM¬O¤@ºØ¤èªk¡A¦ý¬O«Ü¦h®É­Ô¡A§Ú­Ì¹ï°ÝÃDºë½T«×ªº­n¨D¬O¬Û¹ï©ó¨ç¼Æ·í®Éªº­È¡A¦]¦¹­Y³]¦¨¬O¬Y­Ó«Ü¤pªº¼Æ­¼¤W yi ªº¤j¤p eyi¡A¤]¬O«Ü¦X²z¡CµM¦Ó¡A¦pªG³o­Ó¨ç¼Æ¬O·|®¶ÀúÅܤƦӳq¹L¹s¡A§Ú­Ì¤]¥i¯à§Æ±æ¥¦¬O³]©w¬°¬O e ­¼¤W y ¤§³Ì¤j­Èªºµ´¹ï­È¡A¤]¬O¦X²zªº¦Ò¶q¡C¹ê»Ú¤W¼g¦¨µ{¦¡®É¡A¥i¥H¦³¤@¦æ¬O³]¦¨

D0 = eps * yscal(i)

¦pªG y ¬Û¹ïªº¬Û¹ï¤j¤p¬O­«­nªº¡A´N§â¨C¤@·L¨Bªºªì©l y ­È¶Ç¤J¦¨ yscal¡A­Y¬O­n¥Îµ´¹ï®e§Ô­È¡A«h§ï¶Ç¤J©Ò­n©wªº¼Æ­È¡C¦b½Ò¥»©Òªþªº°Æµ{¦¡¤¤¡A¬Æ¦Ü¦h¥[¤F»P±×²v­¼¤W¨B´T¦³Ãöªº¶µ¡A¦Ó§â yscal(x) ³]¦¨¬° |y(x)| + |h*dydx(x)|¡A¤§©Ò¥H·|¦³²Ä¤G¶µªº§Î¦¡¡A¬O¦]¬°§Úªù¤]·|·QºÊ±±¨C¤@·L¨B¤U¨ç¼ÆªºÅܤƶq¡C¡]³o¨ä¤¤ªº½Ñ¦h¦Ò¶q¡A¥i°Ñ¨£½Ò¤åªº¶i¤@¨B²Ó¸`¡C¡^

¦ý¬O¡AD0 ¥X²{¤F h ªº¤@¦¸¥¿¤ñÃö«Y·|¼vÅT¨ì«e­±¶}¤­¦¸¤èªº¤ÀªR¡A©Ò©¯¥|¦¸¤è©Î¤­¦¸¤è¨Ã¤£¬O¨º»ò¤£¦P¡A½Ò¥»§@ªÌ°ò©ó¹ê§@¸gÅç«Øij¤F¤U¦¸³q¥Îªº§PÂ_¾÷¨î¡A°ò¥»¤Wªº·Qªk´N¬O¡A·í¨B´T»Ý­n©ñ¤j¡]²{¦³¨B´T¤Ó«O¦u¡^¡A¥Î¤p¤@ÂIªº¶}¤è­È¡F·í¨B´T»Ý­nÁY¤p¡]²{¦³¨B´T¤Ó¿E¶i¡^¡A¥Î¤j¤@ÂIªº¦¸¤è­È

¨ä¤¤ S ¬O¤@­Ó²¤¤p©ó 1 ªº±`¼Æ¡C

 

 

 

°Æµ{¦¡ªº¨Ï¥Î

½Õ¾A¨B´T±±¨îªº R-K ¤èªk¥Ñ¤U¦C¤@²Õ¤T­Ó°Æµ{¦¡¹F¦¨¡A¨ä¥\¯à²¤­z¦p¤U¡]¦A¦¸±j½Õ¡A¤j®a­n¾Ç·|¦Û¦æ¾\Ū°Æµ{¦¡ªº­^¤å¨Ï¥Î»¡©ú¡A§A¦Û¤w­n¯à¬Ý±o¥X¤U¦C­nÂI¾ã²z©Ò¦CÁ|ªº¨Æ¶µ¡^¡A

odeint¡GÅX°Ê¾¹¡]driver¡^°Æµ{¦¡¡A·|°Ý¦ÛÅܼƽd³ò¡Bªì©l­È¡Bºë«×±±¨î¬ÛÃö±ø¥ó¡A¥H¤Î´£¨Ñ common block Åý¥Dµ{¦¡¦³©ñµª®×ªº¦a¤è¡C

rkqs¡G"«~½èºÞ¨î"¡CºÊ±±¨C­Ó·L¨BªººIÂ_»~®t¡]trancation error¡^¨Ã¥B½Õ¾ã¨B´T ¡C³Q odeint ©I¥s¡A¦Û¤w¦A©I¥s rkck¡C

rkck¡G¯à¶i¦æ¤­¶¥ R-K ¹Bºâªº·L¨Bªº±À¶i¡A¨Ã¥]§t¤º´O¡]embeded¡^4 ¶¥ R-K ¥H¨Ñ§@»~®tºÊ±±¡C

¨Ï¥ÎªÌ¦Û¦æ¶·´£¨Ñªº derivs °Æµ{¦¡·|³Q odeint ¡]¬°¤F§@¨B´T±±¨î¡^ ¥H¤Î³Q rkck ¡]¬°¤F±À¶i¤@·L¨B¡^¨â­Ó°Æµ{¦¡©Ò©I¥s¡C

 

¥H¤U¬O¥¦­Ì¦U¦Ûªº²Ó¸`¡G

rkqs

»Ý­n¨Ï¥ÎªÌ´£¨Ñªº derivs »P¤U­±ªº rkck ¡A¥¦¬O³Q odeint ©I¥s¡A¦Û¤w¦A©I¥s rkck¡A¥Dµ{¦¡»Ý§@«Å§iªºªF¦è¨S¦³¥²¶·°Ñ¦Ò³oùتº¡A¥i·í§@¶Â²°¤l¡C

 

rkck

³o¬O³Ì©³¼hªº·L¨B°Æµ{¦¡¡A¨ã³Æºâ¥X»~®t¦ô­pªº¥\¯à¡AÁöµM¦³ª½±µ¥s¥Î¨ì derivs¡A¦ý³o¥Îªk»P odeint ³B¤@¼Ë¡A¨Ï¥ÎªÌ¼gªº¥Dµ{¦¡¨Ã¤£»Ý­n»P³o­Ó rkck »Î±µ¡A¤]¤£»Ý­n°Ñ¦Ò³oùØÀYªºÅܼƫŧi¡A¥i·í§@¶Â²°¤l¡C

 

odeint

¨Ï¥ÎªÌ©Ò¼gªº¥Dµ{¦¡¡A¥²¶·ª½±µ¥s¥Î odeint¡A ¦]¦¹¦³¦h³B«Å§i¤Wªº²Ó¸`¥²¶·°Ñ¦Ò¡A¤~¯à§â¥D°Æµ{¦¡»Î±µ°_¨Ó¡C¦Ü©ó derivs «h¬O¬Û·í¼Ð·Ç³æ¯Â¡A»P¤W­Ó³æ¤¸¦b rkdumb ªº§@ªk§¹¥þ¤@¼Ë¡C

³o­Ó odeint ¬O rkqs ªº driver µ{¦¡¡A·|§â x1 ~ x2 ½d³ò¤ºªº¨ç¼Æ y(x) °µ¥X¨Ó¡Axn »P yn ªº¼Æ­Èµª®×¬O©ñ¦b¤½¦@°Ï¶ô /path/ ªº xp »P yp ¤¤¡A¦]¦¹¥Dµ{¦¡¤]»Ý­n§@¹ïÀ³ªº«Å§i¤~¯à§â¥¦®³¥X¨Ó¡C

¾\Ū odeint ªº»¡©ú°Ï¶ô¡A§Ú­Ì¥i¥Hª¾¹D¬°¤F¨Ï¥Î³o­Ó°Æµ{¦¡¡A¨Ï¥ÎªÌ¥²¶·¦b¥Dµ{¦¡¤¤¥H parameter ¤è¦¡©w¸q nvar¡A¨Ã¥B­n¿é¤J ystart(i)¡Bx1¡Bx2¡Beps¡Bh1¡Bhmin ³o¨Ç¶q¶Çµ¹ odeint¡C



¨Ï¥Î odeint ¦³¥t¤@­Ó­È±oª`·NªºÂI¡A´N¬O¥¦¬O³]­p¬°±o¨ì³Ì²×­È y(x2) ¬°¥D¡A¦¹°Æµ{¦¡ÁöµM¦³´£¨Ñ¤¤¶¡¹Lµ{ªº­È¡A¦ý¥Ñ©ó¨B´T¤j¤p¤£©T©w¡A¦]¦¹¤¤¶¡¹Lµ{ªºÂI¤£¬O«Ü¾A¦X§@¹Ï¥Î¡]¤£¹³¬O rkdumb ¨º¼Ë¡^¡C¥¦¤º³¡¤´µM¦³³]¸m¤½¦@°Ï¶ô¨Ó½Ñ¦s¤¤¶¡¹Lµ{¡AÁ`¦@¦s¦h¤ÖÂI¬O¥Ñ kmax »P dxsav ¨Ó¨M©w¡A¨Ï¥ÎªÌ­n¦Û¦ó³]©w´N¨â­Ó­È¡A¦p¦P¤W­±¸`¿ý¤§µ{¦¡»¡©ú©Ò¥Ü¡C

¦pªG§Ú­Ì·Q±q odeint ªºµ²ªG¨ú±o¨ä¤½¦@°Ï¶ôùتº¤¤¶¡¹Lµ{¨Ó§@¹Ï©Î¬Ý¨B´TÅܤƪºª¬ªp¡A«hµ½¥Î common block ¤¤¤§ kount ¬O«Ü­«­nªº¡A¥¦¥Nªí¤F¤¤¶¡­ÈªºÂI¼Æ¡C¡]xp(i) ¦b i ¤j©ó kount ¤§«á³£¬O³Q³]¦¨¹s¡A½Ð¤p¤ß¡C¡^

kmax »P dxsav ¨ãÅ骺·N¸q¡A«h¬O¦b½Ò¤å¤¤¥æ«Ý¡]ÁÙ¬O§Æ±æ¤j®a­n¸ÕµÛ¾Ç·|¬ÝÀ´¥¦¡^¡C°ò¥»¤W¬O»¡¡A¶¡¹j¨B´T¤j©ó dxsav ªº¤~·|¦s¤U¨Ó¡A¨Ã¥B¥ý¦s¨ì kmax ¥Îº¡¬°¤î¡A¨âªÌ©TµM³£¬O¨Ï¥ÎªÌ¦Û¦æ³]©w¡A¦ý kmax ³Ì¦h¤£¯à¤j¹L«Å§iªº°}¦C¤j¤p KMAXX ¡C

¦A¦¸¥mÀ{

¦b¥»¾Ç´Áªº¦U³æ¤¸°Æµ{¦¡¤¤¡Aodeint + rkqs + rkck ºâ¬O¤ñ¸û½ÆÂøªº¤@²Õ¡A¦ý¸Ñ±`·L¤À¤èµ{¦¡¬O­«­nªº°ÝÃD¡A¥B³o²Õ°Æµ{¦¡¬O·¥¦³«Â¤Oªx¥Î«¬µ{¦¡¡A¤j®a¤@©w­n½T¹ê½m²ß¡C

 

½d¨Ò¥Dµ{¦¡

c
c This program is written by Prof. Ming-Hsien Lee for demonstrating the use
c of Numerical Recie subroutine ODEINT, RKQS, and RKCK to perform Adaptive
c Step-size Control Runge-Kutta algorithm for solving ordinary differential
c equations. Provided to year 2007 Numerical Methods class.
c

program odeint_main

implicit none
integer nvar,i,nok,nbad
parameter (nvar=2)
real ystart(nvar),x1,x2,eps,h1,hmin

c For common block

integer KMAXX,NMAX,kmax,kount
parameter (KMAXX=200,NMAX=50)
real xp(KMAXX),yp(NMAX,KMAXX),dxsav
common /path/ kmax,kount,dxsav,xp,yp

c For pgplot

integer pgopen,icount,j
real y_min(nvar),y_max(nvar),yy(KMAXX),y_extra

external rkqs,derivs

kmax = KMAXX
dxsav = 0.001

write(*,*) 'What is the beginning and endding of x, x1 ; x2 ?'
read (*,*) x1,x2
write(*,*) 'Input inital vector of yi at x1:'
read (*,*) (ystart(i),i=1,nvar)
write(*,*) 'What is the accuracy eps and first setp size h1 ?'
read (*,*) eps, h1
write(*,*) 'Minimum allowed step size (can be zero) hmin is:'
read (*,*) hmin

call odeint(ystart,nvar,x1,x2,eps,h1,hmin,nok,nbad,derivs,rkqs)
write(*,*) 'Subroutine odeint completed.'
write(*,*) 'Final value of y_i are:'
write(*,*) (ystart(i),i=1,nvar)
write(*,*) 'nok is',nok,' nbad is',nbad
write(*,*) 'The total number of points for plotting is :',kount

c Find Max and min values of yi(x), but here we will use only y1(x).

do i=1,nvar
y_max(i)= yp(i,1)
y_min(i)= yp(i,1)
end do
do i=1,nvar
do j=1,kount
if (yp(i,j).gt.y_max(i)) y_max(i)=yp(i,j)
if (yp(i,j).lt.y_min(i)) y_min(i)=yp(i,j)
end do
end do

c Copy y(1,1:nstep) to yy(1:nstep) for PGLINE plotting

do i=1,kount
yy(i) = yp(1,i)
end do

c  ¡@¡@Intermidiate reult check
c¡@¡@¡@do i=1,kount
c¡@¡@¡@write(*,200) i,xp(i),i, yy(i)
c 200 format(1x,'x(',i3,') is ',f5.2,' y(',i3,') is ',f5.2)
c¡@¡@¡@end do

c Start plotting

y_extra = 0.1*(y_max(1)-y_min(1))
if (pgopen('/xwin').le.0) stop
call pgpap(6.0,0.75)
call pgenv (x1,x2,y_min(1)-y_extra,y_max(1)+y_extra,0,0)
call pgline(kount,xp,yy)
call pgsci(2)
call pgpt(kount,xp,yy,9)
call pgclos

end

subroutine derivs(x,y,dydx)
real x,y(2),dydx(2)
dydx(1) = y(2)
dydx(2) = -y(1)
end

c ¡@¡@subroutine derivs(x,y,dydx)
c ¡@¡@real x,y,dydx
c ¡@¡@dydx = 2*x
c ¡@¡@end

 

µù¡G¤W¨ÒªºÃD¥Ø¬O y"(x) + y(x) = 0¡A¦Ó comment ±¼ªº¥t¤@­Ó¨ÒÃD«h¬O y'(x) = 2x¡C