home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / meschach / !Meschach / c / zcopy < prev    next >
Unknown  |  1994-01-12  |  5.1 KB

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text


This file was not able to be converted.
This format is not currently supported by dexvert.

ConfidenceProgramDetectionMatch TypeSupport
100% file data default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 3d 3d 3d 3d 3d 3d 3d 3d | 3d 3d 3d 3d 3d 3d 2a 2f |========|======*/|
|00000010| 0a 0a 63 68 61 72 20 2a | 6d 33 64 5f 6e 61 6d 65 |..char *|m3d_name|
|00000020| 73 5b 5d 20 3d 20 7b 0a | 20 20 22 4d 41 54 33 44 |s[] = {.| "MAT3D|
|00000030| 22 0a 7d 3b 0a 0a 0a 23 | 64 65 66 69 6e 65 20 4d |".};...#|define M|
|00000040| 33 44 5f 4e 55 4d 20 20 | 28 73 69 7a 65 6f 66 28 |3D_NUM |(sizeof(|
|00000050| 6d 33 64 5f 6e 61 6d 65 | 73 29 2f 73 69 7a 65 6f |m3d_name|s)/sizeo|
|00000060| 66 28 2a 6d 33 64 5f 6e | 61 6d 65 73 29 29 0a 0a |f(*m3d_n|ames))..|
|00000070| 69 6e 74 20 28 2a 6d 33 | 64 5f 66 72 65 65 5f 66 |int (*m3|d_free_f|
|00000080| 75 6e 63 73 5b 4d 33 44 | 5f 4e 55 4d 5d 29 28 29 |uncs[M3D|_NUM])()|
|00000090| 20 3d 20 7b 0a 20 20 6d | 33 64 5f 66 72 65 65 0a | = {. m|3d_free.|
|000000a0| 7d 3b 0a 0a 73 74 61 74 | 69 63 20 4d 45 4d 5f 41 |};..stat|ic MEM_A|
|000000b0| 52 52 41 59 20 6d 33 64 | 5f 73 75 6d 5b 4d 33 44 |RRAY m3d|_sum[M3D|
|000000c0| 5f 4e 55 4d 5d 3b 0a 0a | 0a 2f 2a 20 74 65 73 74 |_NUM];..|./* test|
|000000d0| 20 72 6f 75 74 69 6e 67 | 20 66 6f 72 20 61 6c 6c | routing| for all|
|000000e0| 6f 63 61 74 69 6e 67 2f | 64 65 61 6c 6c 6f 63 61 |ocating/|dealloca|
|000000f0| 74 69 6e 67 20 73 74 61 | 74 69 63 20 76 61 72 69 |ting sta|tic vari|
|00000100| 61 62 6c 65 73 20 2a 2f | 0a 76 6f 69 64 20 74 65 |ables */|.void te|
|00000110| 73 74 5f 73 74 61 74 28 | 6b 29 0a 69 6e 74 20 6b |st_stat(|k).int k|
|00000120| 3b 0a 7b 0a 20 20 20 73 | 74 61 74 69 63 20 4d 41 |;.{. s|tatic MA|
|00000130| 54 33 44 20 2a 77 6f 72 | 6b 3b 0a 0a 20 20 20 69 |T3D *wor|k;.. i|
|00000140| 66 20 28 21 77 6f 72 6b | 29 20 7b 0a 20 20 20 20 |f (!work|) {. |
|00000150| 20 20 77 6f 72 6b 20 3d | 20 6d 33 64 5f 67 65 74 | work =| m3d_get|
|00000160| 28 31 30 2c 31 30 2c 31 | 30 29 3b 0a 20 20 20 20 |(10,10,1|0);. |
|00000170| 20 20 6d 65 6d 5f 73 74 | 61 74 5f 72 65 67 5f 6c | mem_st|at_reg_l|
|00000180| 69 73 74 28 28 76 6f 69 | 64 20 2a 2a 29 26 77 6f |ist((voi|d **)&wo|
|00000190| 72 6b 2c 54 59 50 45 5f | 4d 41 54 33 44 2c 4d 33 |rk,TYPE_|MAT3D,M3|
|000001a0| 44 5f 4c 49 53 54 29 3b | 0a 20 20 20 20 20 20 77 |D_LIST);|. w|
|000001b0| 6f 72 6b 2d 3e 6d 65 5b | 39 5d 5b 39 5d 5b 39 5d |ork->me[|9][9][9]|
|000001c0| 20 3d 20 2d 33 2e 31 34 | 3b 0a 20 20 20 7d 0a 20 | = -3.14|;. }. |
|000001d0| 20 20 0a 20 20 20 69 66 | 20 28 6b 20 3d 3d 20 39 | . if| (k == 9|
|000001e0| 29 20 0a 20 20 20 20 20 | 70 72 69 6e 74 66 28 22 |) . |printf("|
|000001f0| 20 77 6f 72 6b 5b 39 5d | 5b 39 5d 5b 39 5d 20 3d | work[9]|[9][9] =|
|00000200| 20 25 67 5c 6e 22 2c 77 | 6f 72 6b 2d 3e 6d 65 5b | %g\n",w|ork->me[|
|00000210| 39 5d 5b 39 5d 5b 39 5d | 29 3b 0a 7d 0a 0a 0a 76 |9][9][9]|);.}...v|
|00000220| 6f 69 64 20 6d 61 69 6e | 28 29 0a 7b 0a 20 20 4d |oid main|().{. M|
|00000230| 41 54 33 44 20 2a 4d 3b | 0a 20 20 69 6e 74 20 69 |AT3D *M;|. int i|
|00000240| 2c 6a 2c 6b 3b 0a 0a 20 | 20 6d 65 6d 5f 69 6e 66 |,j,k;.. | mem_inf|
|00000250| 6f 5f 6f 6e 28 54 52 55 | 45 29 3b 0a 20 20 2f 2a |o_on(TRU|E);. /*|
|00000260| 20 63 61 6e 20 62 65 20 | 74 68 65 20 66 69 72 73 | can be |the firs|
|00000270| 74 20 63 6f 6d 6d 61 6e | 64 20 2a 2f 0a 20 20 6d |t comman|d */. m|
|00000280| 65 6d 5f 61 74 74 61 63 | 68 5f 6c 69 73 74 28 4d |em_attac|h_list(M|
|00000290| 33 44 5f 4c 49 53 54 2c | 4d 33 44 5f 4e 55 4d 2c |3D_LIST,|M3D_NUM,|
|000002a0| 6d 33 64 5f 6e 61 6d 65 | 73 2c 6d 33 64 5f 66 72 |m3d_name|s,m3d_fr|
|000002b0| 65 65 5f 66 75 6e 63 73 | 2c 6d 33 64 5f 73 75 6d |ee_funcs|,m3d_sum|
|000002c0| 29 3b 0a 0a 20 20 4d 20 | 3d 20 6d 33 64 5f 67 65 |);.. M |= m3d_ge|
|000002d0| 74 28 33 2c 34 2c 35 29 | 3b 0a 20 20 6d 65 6d 5f |t(3,4,5)|;. mem_|
|000002e0| 69 6e 66 6f 5f 66 69 6c | 65 28 73 74 64 6f 75 74 |info_fil|e(stdout|
|000002f0| 2c 4d 33 44 5f 4c 49 53 | 54 29 3b 0a 0a 20 20 2f |,M3D_LIS|T);.. /|
|00000300| 2a 20 6d 61 6b 65 20 75 | 73 65 20 6f 66 20 4d 2d |* make u|se of M-|
|00000310| 3e 6d 65 5b 69 5d 5b 6a | 5d 5b 6b 5d 2c 20 77 68 |>me[i][j|][k], wh|
|00000320| 65 72 65 20 69 2c 6a 2c | 6b 20 61 72 65 20 6e 6f |ere i,j,|k are no|
|00000330| 6e 2d 6e 65 67 61 74 69 | 76 65 20 61 6e 64 20 0a |n-negati|ve and .|
|00000340| 09 69 20 3c 20 33 2c 20 | 6a 20 3c 20 34 2c 20 6b |.i < 3, |j < 4, k|
|00000350| 20 3c 20 35 20 2a 2f 0a | 0a 20 20 6d 65 6d 5f 73 | < 5 */.|. mem_s|
|00000360| 74 61 74 5f 6d 61 72 6b | 28 31 29 3b 0a 20 20 66 |tat_mark|(1);. f|
|00000370| 6f 72 20 28 69 3d 30 3b | 20 69 20 3c 20 33 3b 20 |or (i=0;| i < 3; |
|00000380| 69 2b 2b 29 0a 20 20 20 | 20 66 6f 72 20 28 6a 3d |i++). | for (j=|
|00000390| 30 3b 20 6a 20 3c 20 34 | 3b 20 6a 2b 2b 29 0a 20 |0; j < 4|; j++). |
|000003a0| 20 20 20 20 20 66 6f 72 | 20 28 6b 3d 30 3b 20 6b | for| (k=0; k|
|000003b0| 20 3c 20 35 3b 20 6b 2b | 2b 29 20 7b 0a 09 20 74 | < 5; k+|+) {.. t|
|000003c0| 65 73 74 5f 73 74 61 74 | 28 69 2b 6a 2b 6b 29 3b |est_stat|(i+j+k);|
|000003d0| 0a 09 20 4d 2d 3e 6d 65 | 5b 69 5d 5b 6a 5d 5b 6b |.. M->me|[i][j][k|
|000003e0| 5d 20 3d 20 69 2b 6a 2b | 6b 3b 0a 20 20 20 20 20 |] = i+j+|k;. |
|000003f0| 20 7d 0a 20 20 6d 65 6d | 5f 73 74 61 74 5f 66 72 | }. mem|_stat_fr|
|00000400| 65 65 5f 6c 69 73 74 28 | 31 2c 4d 33 44 5f 4c 49 |ee_list(|1,M3D_LI|
|00000410| 53 54 29 3b 0a 20 20 6d | 65 6d 5f 69 6e 66 6f 5f |ST);. m|em_info_|
|00000420| 66 69 6c 65 28 73 74 64 | 6f 75 74 2c 4d 33 44 5f |file(std|out,M3D_|
|00000430| 4c 49 53 54 29 3b 0a 0a | 20 20 70 72 69 6e 74 66 |LIST);..| printf|
|00000440| 28 22 20 4d 5b 25 64 5d | 5b 25 64 5d 5b 25 64 5d |(" M[%d]|[%d][%d]|
|00000450| 20 3d 20 25 67 5c 6e 22 | 2c 32 2c 33 2c 34 2c 4d | = %g\n"|,2,3,4,M|
|00000460| 2d 3e 6d 65 5b 32 5d 5b | 33 5d 5b 34 5d 29 3b 0a |->me[2][|3][4]);.|
|00000470| 0a 20 20 6d 65 6d 5f 73 | 74 61 74 5f 6d 61 72 6b |. mem_s|tat_mark|
|00000480| 28 32 29 3b 0a 20 20 74 | 65 73 74 5f 73 74 61 74 |(2);. t|est_stat|
|00000490| 28 39 29 3b 0a 20 20 6d | 65 6d 5f 73 74 61 74 5f |(9);. m|em_stat_|
|000004a0| 66 72 65 65 5f 6c 69 73 | 74 28 32 2c 4d 33 44 5f |free_lis|t(2,M3D_|
|000004b0| 4c 49 53 54 29 3b 0a 0a | 20 20 6d 33 64 5f 66 72 |LIST);..| m3d_fr|
|000004c0| 65 65 28 4d 29 3b 20 20 | 2f 2a 20 69 66 20 4d 20 |ee(M); |/* if M |
|000004d0| 69 73 20 6e 6f 74 20 6e | 65 63 65 73 73 61 72 79 |is not n|ecessary|
|000004e0| 20 2a 2f 0a 20 20 6d 65 | 6d 5f 69 6e 66 6f 5f 66 | */. me|m_info_f|
|000004f0| 69 6c 65 28 73 74 64 6f | 75 74 2c 4d 33 44 5f 4c |ile(stdo|ut,M3D_L|
|00000500| 49 53 54 29 3b 0a 0a 7d | 0a 0a 0a 0a 46 69 6c 65 |IST);..}|....File|
|00000510| 44 61 74 61 82 74 75 74 | 6f 72 69 61 6c 00 00 00 |Data.tut|orial...|
|00000520| 57 1e 00 00 45 ff ff ff | 74 96 20 58 03 00 86 40 |W...E...|t. X...@|
|00000530| 0a 2f 2a 2a 2a 2a 2a 2a | 2a 2a 2a 2a 2a 2a 2a 2a |./******|********|
|00000540| 2a 2a 2a 2a 2a 2a 2a 2a | 2a 2a 2a 2a 2a 2a 2a 2a |********|********|
|00000550| 2a 2a 2a 2a 2a 2a 2a 2a | 2a 2a 2a 2a 2a 2a 2a 2a |********|********|
|00000560| 2a 2a 2a 2a 2a 2a 2a 2a | 2a 2a 2a 2a 2a 2a 2a 2a |********|********|
|00000570| 2a 2a 2a 2a 2a 2a 2a 2a | 2a 2a 2a 2a 0a 2a 2a 0a |********|****.**.|
|00000580| 2a 2a 20 43 6f 70 79 72 | 69 67 68 74 20 28 43 29 |** Copyr|ight (C)|
|00000590| 20 31 39 39 33 20 44 61 | 76 69 64 20 45 2e 20 53 | 1993 Da|vid E. S|
|000005a0| 74 65 77 61 72 64 20 26 | 20 5a 62 69 67 6e 69 65 |teward &| Zbignie|
|000005b0| 77 20 4c 65 79 6b 2c 20 | 61 6c 6c 20 72 69 67 68 |w Leyk, |all righ|
|000005c0| 74 73 20 72 65 73 65 72 | 76 65 64 2e 0a 2a 2a 0a |ts reser|ved..**.|
|000005d0| 2a 2a 09 09 09 20 20 20 | 20 20 4d 65 73 63 68 61 |**... | Mescha|
|000005e0| 63 68 20 4c 69 62 72 61 | 72 79 0a 2a 2a 20 0a 2a |ch Libra|ry.** .*|
|000005f0| 2a 20 54 68 69 73 20 4d | 65 73 63 68 61 63 68 20 |* This M|eschach |
|00000600| 4c 69 62 72 61 72 79 20 | 69 73 20 70 72 6f 76 69 |Library |is provi|
|00000610| 64 65 64 20 22 61 73 20 | 69 73 22 20 77 69 74 68 |ded "as |is" with|
|00000620| 6f 75 74 20 61 6e 79 20 | 65 78 70 72 65 73 73 20 |out any |express |
|00000630| 0a 2a 2a 20 6f 72 20 69 | 6d 70 6c 69 65 64 20 77 |.** or i|mplied w|
|00000640| 61 72 72 61 6e 74 79 20 | 6f 66 20 61 6e 79 20 6b |arranty |of any k|
|00000650| 69 6e 64 20 77 69 74 68 | 20 72 65 73 70 65 63 74 |ind with| respect|
|00000660| 20 74 6f 20 74 68 69 73 | 20 73 6f 66 74 77 61 72 | to this| softwar|
|00000670| 65 2e 20 0a 2a 2a 20 49 | 6e 20 70 61 72 74 69 63 |e. .** I|n partic|
|00000680| 75 6c 61 72 20 74 68 65 | 20 61 75 74 68 6f 72 73 |ular the| authors|
|00000690| 20 73 68 61 6c 6c 20 6e | 6f 74 20 62 65 20 6c 69 | shall n|ot be li|
|000006a0| 61 62 6c 65 20 66 6f 72 | 20 61 6e 79 20 64 69 72 |able for| any dir|
|000006b0| 65 63 74 2c 20 0a 2a 2a | 20 69 6e 64 69 72 65 63 |ect, .**| indirec|
|000006c0| 74 2c 20 73 70 65 63 69 | 61 6c 2c 20 69 6e 63 69 |t, speci|al, inci|
|000006d0| 64 65 6e 74 61 6c 20 6f | 72 20 63 6f 6e 73 65 71 |dental o|r conseq|
|000006e0| 75 65 6e 74 69 61 6c 20 | 64 61 6d 61 67 65 73 20 |uential |damages |
|000006f0| 61 72 69 73 69 6e 67 20 | 0a 2a 2a 20 69 6e 20 61 |arising |.** in a|
|00000700| 6e 79 20 77 61 79 20 66 | 72 6f 6d 20 75 73 65 20 |ny way f|rom use |
|00000710| 6f 66 20 74 68 65 20 73 | 6f 66 74 77 61 72 65 2e |of the s|oftware.|
|00000720| 0a 2a 2a 20 0a 2a 2a 20 | 45 76 65 72 79 6f 6e 65 |.** .** |Everyone|
|00000730| 20 69 73 20 67 72 61 6e | 74 65 64 20 70 65 72 6d | is gran|ted perm|
|00000740| 69 73 73 69 6f 6e 20 74 | 6f 20 63 6f 70 79 2c 20 |ission t|o copy, |
|00000750| 6d 6f 64 69 66 79 20 61 | 6e 64 20 72 65 64 69 73 |modify a|nd redis|
|00000760| 74 72 69 62 75 74 65 20 | 74 68 69 73 0a 2a 2a 20 |tribute |this.** |
|00000770| 4d 65 73 63 68 61 63 68 | 20 4c 69 62 72 61 72 79 |Meschach| Library|
|00000780| 2c 20 70 72 6f 76 69 64 | 65 64 3a 0a 2a 2a 20 20 |, provid|ed:.** |
|00000790| 31 2e 20 20 41 6c 6c 20 | 63 6f 70 69 65 73 20 63 |1. All |copies c|
|000007a0| 6f 6e 74 61 69 6e 20 74 | 68 69 73 20 63 6f 70 79 |ontain t|his copy|
|000007b0| 72 69 67 68 74 20 6e 6f | 74 69 63 65 2e 0a 2a 2a |right no|tice..**|
|000007c0| 20 20 32 2e 20 20 41 6c | 6c 20 6d 6f 64 69 66 69 | 2. Al|l modifi|
|000007d0| 65 64 20 63 6f 70 69 65 | 73 20 73 68 61 6c 6c 20 |ed copie|s shall |
|000007e0| 63 61 72 72 79 20 61 20 | 6e 6f 74 69 63 65 20 73 |carry a |notice s|
|000007f0| 74 61 74 69 6e 67 20 77 | 68 6f 0a 2a 2a 20 20 20 |tating w|ho.** |
|00000800| 20 20 20 6d 61 64 65 20 | 74 68 65 20 6c 61 73 74 | made |the last|
|00000810| 20 6d 6f 64 69 66 69 63 | 61 74 69 6f 6e 20 61 6e | modific|ation an|
|00000820| 64 20 74 68 65 20 64 61 | 74 65 20 6f 66 20 73 75 |d the da|te of su|
|00000830| 63 68 20 6d 6f 64 69 66 | 69 63 61 74 69 6f 6e 2e |ch modif|ication.|
|00000840| 0a 2a 2a 20 20 33 2e 20 | 20 4e 6f 20 63 68 61 72 |.** 3. | No char|
|00000850| 67 65 20 69 73 20 6d 61 | 64 65 20 66 6f 72 20 74 |ge is ma|de for t|
|00000860| 68 69 73 20 73 6f 66 74 | 77 61 72 65 20 6f 72 20 |his soft|ware or |
|00000870| 77 6f 72 6b 73 20 64 65 | 72 69 76 65 64 20 66 72 |works de|rived fr|
|00000880| 6f 6d 20 69 74 2e 20 20 | 0a 2a 2a 20 20 20 20 20 |om it. |.** |
|00000890| 20 54 68 69 73 20 63 6c | 61 75 73 65 20 73 68 61 | This cl|ause sha|
|000008a0| 6c 6c 20 6e 6f 74 20 62 | 65 20 63 6f 6e 73 74 72 |ll not b|e constr|
|000008b0| 75 65 64 20 61 73 20 63 | 6f 6e 73 74 72 61 69 6e |ued as c|onstrain|
|000008c0| 69 6e 67 20 6f 74 68 65 | 72 20 73 6f 66 74 77 61 |ing othe|r softwa|
|000008d0| 72 65 0a 2a 2a 20 20 20 | 20 20 20 64 69 73 74 72 |re.** | distr|
|000008e0| 69 62 75 74 65 64 20 6f | 6e 20 74 68 65 20 73 61 |ibuted o|n the sa|
|000008f0| 6d 65 20 6d 65 64 69 75 | 6d 20 61 73 20 74 68 69 |me mediu|m as thi|
|00000900| 73 20 73 6f 66 74 77 61 | 72 65 2c 20 6e 6f 72 20 |s softwa|re, nor |
|00000910| 69 73 20 61 0a 2a 2a 20 | 20 20 20 20 20 64 69 73 |is a.** | dis|
|00000920| 74 72 69 62 75 74 69 6f | 6e 20 66 65 65 20 63 6f |tributio|n fee co|
|00000930| 6e 73 69 64 65 72 65 64 | 20 61 20 63 68 61 72 67 |nsidered| a charg|
|00000940| 65 2e 0a 2a 2a 0a 2a 2a | 2a 2a 2a 2a 2a 2a 2a 2a |e..**.**|********|
|00000950| 2a 2a 2a 2a 2a 2a 2a 2a | 2a 2a 2a 2a 2a 2a 2a 2a |********|********|
|00000960| 2a 2a 2a 2a 2a 2a 2a 2a | 2a 2a 2a 2a 2a 2a 2a 2a |********|********|
|00000970| 2a 2a 2a 2a 2a 2a 2a 2a | 2a 2a 2a 2a 2a 2a 2a 2a |********|********|
|00000980| 2a 2a 2a 2a 2a 2a 2a 2a | 2a 2a 2a 2a 2a 2a 2a 2a |********|********|
|00000990| 2a 2f 0a 0a 2f 2a 20 74 | 75 74 6f 72 69 61 6c 2e |*/../* t|utorial.|
|000009a0| 63 20 31 30 2f 31 32 2f | 31 39 39 33 20 2a 2f 0a |c 10/12/|1993 */.|
|000009b0| 0a 2f 2a 20 72 6f 75 74 | 69 6e 65 73 20 66 72 6f |./* rout|ines fro|
|000009c0| 6d 20 43 68 61 70 74 65 | 72 20 31 20 6f 66 20 4d |m Chapte|r 1 of M|
|000009d0| 65 73 63 68 61 63 68 20 | 2a 2f 0a 0a 73 74 61 74 |eschach |*/..stat|
|000009e0| 69 63 20 63 68 61 72 20 | 72 63 73 69 64 5b 5d 20 |ic char |rcsid[] |
|000009f0| 3d 20 22 24 49 64 3a 20 | 74 75 74 6f 72 69 61 6c |= "$Id: |tutorial|
|00000a00| 2e 63 2c 76 20 31 2e 33 | 20 31 39 39 34 2f 30 31 |.c,v 1.3| 1994/01|
|00000a10| 2f 31 36 20 32 32 3a 35 | 33 3a 30 39 20 64 65 73 |/16 22:5|3:09 des|
|00000a20| 20 45 78 70 20 24 22 3b | 0a 0a 23 69 6e 63 6c 75 | Exp $";|..#inclu|
|00000a30| 64 65 20 3c 6d 61 74 68 | 2e 68 3e 0a 23 69 6e 63 |de <math|.h>.#inc|
|00000a40| 6c 75 64 65 20 22 6d 61 | 74 72 69 78 2e 68 22 0a |lude "ma|trix.h".|
|00000a50| 0a 2f 2a 20 72 6b 34 20 | 2d 2d 20 34 74 68 20 6f |./* rk4 |-- 4th o|
|00000a60| 72 64 65 72 20 52 75 6e | 67 65 2d 2d 4b 75 74 74 |rder Run|ge--Kutt|
|00000a70| 61 20 6d 65 74 68 6f 64 | 20 2a 2f 0a 64 6f 75 62 |a method| */.doub|
|00000a80| 6c 65 20 72 6b 34 28 66 | 2c 74 2c 78 2c 68 29 0a |le rk4(f|,t,x,h).|
|00000a90| 64 6f 75 62 6c 65 20 74 | 2c 20 68 3b 0a 56 45 43 |double t|, h;.VEC|
|00000aa0| 20 20 20 20 2a 28 2a 66 | 29 28 29 2c 20 2a 78 3b | *(*f|)(), *x;|
|00000ab0| 0a 7b 0a 20 20 20 73 74 | 61 74 69 63 20 56 45 43 |.{. st|atic VEC|
|00000ac0| 20 2a 76 31 3d 56 4e 55 | 4c 4c 2c 20 2a 76 32 3d | *v1=VNU|LL, *v2=|
|00000ad0| 56 4e 55 4c 4c 2c 20 2a | 76 33 3d 56 4e 55 4c 4c |VNULL, *|v3=VNULL|
|00000ae0| 2c 20 2a 76 34 3d 56 4e | 55 4c 4c 3b 0a 20 20 20 |, *v4=VN|ULL;. |
|00000af0| 73 74 61 74 69 63 20 56 | 45 43 20 2a 74 65 6d 70 |static V|EC *temp|
|00000b00| 3d 56 4e 55 4c 4c 3b 0a | 20 20 20 0a 20 20 20 2f |=VNULL;.| . /|
|00000b10| 2a 20 64 6f 20 6e 6f 74 | 20 77 6f 72 6b 20 77 69 |* do not| work wi|
|00000b20| 74 68 20 4e 55 4c 4c 20 | 69 6e 69 74 69 61 6c 20 |th NULL |initial |
|00000b30| 76 65 63 74 6f 72 20 2a | 2f 0a 20 20 20 69 66 20 |vector *|/. if |
|00000b40| 28 20 78 20 3d 3d 20 56 | 4e 55 4c 4c 20 29 0a 20 |( x == V|NULL ). |
|00000b50| 20 20 20 20 65 72 72 6f | 72 28 45 5f 4e 55 4c 4c | erro|r(E_NULL|
|00000b60| 2c 22 72 6b 34 22 29 3b | 0a 0a 20 20 20 2f 2a 20 |,"rk4");|.. /* |
|00000b70| 65 6e 73 75 72 65 20 74 | 68 61 74 20 76 31 2c 20 |ensure t|hat v1, |
|00000b80| 2e 2e 2e 2c 20 76 34 2c | 20 74 65 6d 70 20 61 72 |..., v4,| temp ar|
|00000b90| 65 20 6f 66 20 74 68 65 | 20 63 6f 72 72 65 63 74 |e of the| correct|
|00000ba0| 20 73 69 7a 65 20 2a 2f | 0a 20 20 20 76 31 20 20 | size */|. v1 |
|00000bb0| 20 3d 20 76 5f 72 65 73 | 69 7a 65 28 76 31 2c 78 | = v_res|ize(v1,x|
|00000bc0| 2d 3e 64 69 6d 29 3b 0a | 20 20 20 76 32 20 20 20 |->dim);.| v2 |
|00000bd0| 3d 20 76 5f 72 65 73 69 | 7a 65 28 76 32 2c 78 2d |= v_resi|ze(v2,x-|
|00000be0| 3e 64 69 6d 29 3b 0a 20 | 20 20 76 33 20 20 20 3d |>dim);. | v3 =|
|00000bf0| 20 76 5f 72 65 73 69 7a | 65 28 76 33 2c 78 2d 3e | v_resiz|e(v3,x->|
|00000c00| 64 69 6d 29 3b 0a 20 20 | 20 76 34 20 20 20 3d 20 |dim);. | v4 = |
|00000c10| 76 5f 72 65 73 69 7a 65 | 28 76 34 2c 78 2d 3e 64 |v_resize|(v4,x->d|
|00000c20| 69 6d 29 3b 0a 20 20 20 | 74 65 6d 70 20 3d 20 76 |im);. |temp = v|
|00000c30| 5f 72 65 73 69 7a 65 28 | 74 65 6d 70 2c 78 2d 3e |_resize(|temp,x->|
|00000c40| 64 69 6d 29 3b 0a 0a 20 | 20 20 2f 2a 20 72 65 67 |dim);.. | /* reg|
|00000c50| 69 73 74 65 72 20 77 6f | 72 6b 73 70 61 63 65 20 |ister wo|rkspace |
|00000c60| 76 61 72 69 61 62 6c 65 | 73 20 2a 2f 0a 20 20 20 |variable|s */. |
|00000c70| 4d 45 4d 5f 53 54 41 54 | 5f 52 45 47 28 76 31 2c |MEM_STAT|_REG(v1,|
|00000c80| 54 59 50 45 5f 56 45 43 | 29 3b 0a 20 20 20 4d 45 |TYPE_VEC|);. ME|
|00000c90| 4d 5f 53 54 41 54 5f 52 | 45 47 28 76 32 2c 54 59 |M_STAT_R|EG(v2,TY|
|00000ca0| 50 45 5f 56 45 43 29 3b | 0a 20 20 20 4d 45 4d 5f |PE_VEC);|. MEM_|
|00000cb0| 53 54 41 54 5f 52 45 47 | 28 76 33 2c 54 59 50 45 |STAT_REG|(v3,TYPE|
|00000cc0| 5f 56 45 43 29 3b 0a 20 | 20 20 4d 45 4d 5f 53 54 |_VEC);. | MEM_ST|
|00000cd0| 41 54 5f 52 45 47 28 76 | 34 2c 54 59 50 45 5f 56 |AT_REG(v|4,TYPE_V|
|00000ce0| 45 43 29 3b 0a 20 20 20 | 4d 45 4d 5f 53 54 41 54 |EC);. |MEM_STAT|
|00000cf0| 5f 52 45 47 28 74 65 6d | 70 2c 54 59 50 45 5f 56 |_REG(tem|p,TYPE_V|
|00000d00| 45 43 29 3b 0a 20 20 20 | 2f 2a 20 65 6e 64 20 6f |EC);. |/* end o|
|00000d10| 66 20 6d 65 6d 6f 72 79 | 20 61 6c 6c 6f 63 61 74 |f memory| allocat|
|00000d20| 69 6f 6e 20 2a 2f 0a 0a | 20 20 20 28 2a 66 29 28 |ion */..| (*f)(|
|00000d30| 74 2c 78 2c 76 31 29 3b | 20 2f 2a 20 6d 6f 73 74 |t,x,v1);| /* most|
|00000d40| 20 63 6f 6d 70 69 6c 65 | 72 73 20 61 6c 6c 6f 77 | compile|rs allow|
|00000d50| 3a 20 22 66 28 74 2c 78 | 2c 76 31 29 3b 22 20 2a |: "f(t,x|,v1);" *|
|00000d60| 2f 0a 20 20 20 76 5f 6d | 6c 74 61 64 64 28 78 2c |/. v_m|ltadd(x,|
|00000d70| 76 31 2c 30 2e 35 2a 68 | 2c 74 65 6d 70 29 3b 20 |v1,0.5*h|,temp); |
|00000d80| 20 20 20 2f 2a 20 74 65 | 6d 70 20 3d 20 78 2b 2e | /* te|mp = x+.|
|00000d90| 35 2a 68 2a 76 31 20 2a | 2f 0a 20 20 20 28 2a 66 |5*h*v1 *|/. (*f|
|00000da0| 29 28 74 2b 30 2e 35 2a | 68 2c 74 65 6d 70 2c 76 |)(t+0.5*|h,temp,v|
|00000db0| 32 29 3b 0a 20 20 20 76 | 5f 6d 6c 74 61 64 64 28 |2);. v|_mltadd(|
|00000dc0| 78 2c 76 32 2c 30 2e 35 | 2a 68 2c 74 65 6d 70 29 |x,v2,0.5|*h,temp)|
|00000dd0| 3b 20 20 20 20 2f 2a 20 | 74 65 6d 70 20 3d 20 78 |; /* |temp = x|
|00000de0| 2b 2e 35 2a 68 2a 76 32 | 20 2a 2f 0a 20 20 20 28 |+.5*h*v2| */. (|
|00000df0| 2a 66 29 28 74 2b 30 2e | 35 2a 68 2c 74 65 6d 70 |*f)(t+0.|5*h,temp|
|00000e00| 2c 76 33 29 3b 0a 20 20 | 20 76 5f 6d 6c 74 61 64 |,v3);. | v_mltad|
|00000e10| 64 28 78 2c 76 33 2c 68 | 2c 74 65 6d 70 29 3b 20 |d(x,v3,h|,temp); |
|00000e20| 20 20 20 20 20 20 20 2f | 2a 20 74 65 6d 70 20 3d | /|* temp =|
|00000e30| 20 78 2b 68 2a 76 33 20 | 2a 2f 0a 20 20 20 28 2a | x+h*v3 |*/. (*|
|00000e40| 66 29 28 74 2b 68 2c 74 | 65 6d 70 2c 76 34 29 3b |f)(t+h,t|emp,v4);|
|00000e50| 0a 20 20 20 0a 20 20 20 | 2f 2a 20 6e 6f 77 20 61 |. . |/* now a|
|00000e60| 64 64 3a 20 76 31 2b 32 | 2a 76 32 2b 32 2a 76 33 |dd: v1+2|*v2+2*v3|
|00000e70| 2b 76 34 20 2a 2f 0a 20 | 20 20 76 5f 63 6f 70 79 |+v4 */. | v_copy|
|00000e80| 28 76 31 2c 74 65 6d 70 | 29 3b 20 20 20 20 20 20 |(v1,temp|); |
|00000e90| 20 20 20 20 20 20 20 20 | 2f 2a 20 74 65 6d 70 20 | |/* temp |
|00000ea0| 3d 20 76 31 20 2a 2f 0a | 20 20 20 76 5f 6d 6c 74 |= v1 */.| v_mlt|
|00000eb0| 61 64 64 28 74 65 6d 70 | 2c 76 32 2c 32 2e 30 2c |add(temp|,v2,2.0,|
|00000ec0| 74 65 6d 70 29 3b 20 20 | 20 2f 2a 20 74 65 6d 70 |temp); | /* temp|
|00000ed0| 20 3d 20 76 31 2b 32 2a | 76 32 20 2a 2f 0a 20 20 | = v1+2*|v2 */. |
|00000ee0| 20 76 5f 6d 6c 74 61 64 | 64 28 74 65 6d 70 2c 76 | v_mltad|d(temp,v|
|00000ef0| 33 2c 32 2e 30 2c 74 65 | 6d 70 29 3b 20 20 20 2f |3,2.0,te|mp); /|
|00000f00| 2a 20 74 65 6d 70 20 3d | 20 76 31 2b 32 2a 76 32 |* temp =| v1+2*v2|
|00000f10| 2b 32 2a 76 33 20 2a 2f | 0a 20 20 20 76 5f 61 64 |+2*v3 */|. v_ad|
|00000f20| 64 28 74 65 6d 70 2c 76 | 34 2c 74 65 6d 70 29 3b |d(temp,v|4,temp);|
|00000f30| 20 20 20 20 20 20 20 20 | 20 20 2f 2a 20 74 65 6d | | /* tem|
|00000f40| 70 20 3d 20 76 31 2b 32 | 2a 76 32 2b 32 2a 76 33 |p = v1+2|*v2+2*v3|
|00000f50| 2b 76 34 20 2a 2f 0a 20 | 20 20 0a 20 20 20 2f 2a |+v4 */. | . /*|
|00000f60| 20 61 64 6a 75 73 74 20 | 78 20 2a 2f 0a 20 20 20 | adjust |x */. |
|00000f70| 76 5f 6d 6c 74 61 64 64 | 28 78 2c 74 65 6d 70 2c |v_mltadd|(x,temp,|
|00000f80| 68 2f 36 2e 30 2c 78 29 | 3b 20 20 20 20 20 2f 2a |h/6.0,x)|; /*|
|00000f90| 20 78 20 3d 20 78 2b 28 | 68 2f 36 29 2a 74 65 6d | x = x+(|h/6)*tem|
|00000fa0| 70 20 2a 2f 0a 20 20 20 | 0a 20 20 20 72 65 74 75 |p */. |. retu|
|00000fb0| 72 6e 20 74 2b 68 3b 20 | 20 20 20 20 20 20 20 20 |rn t+h; | |
|00000fc0| 20 20 20 20 20 20 20 20 | 20 20 2f 2a 20 72 65 74 | | /* ret|
|00000fd0| 75 72 6e 20 74 68 65 20 | 6e 65 77 20 74 69 6d 65 |urn the |new time|
|00000fe0| 20 2a 2f 0a 7d 0a 0a 0a | 0a 2f 2a 20 72 6b 34 20 | */.}...|./* rk4 |
|00000ff0| 2d 2d 20 34 74 68 20 6f | 72 64 65 72 20 52 75 6e |-- 4th o|rder Run|
|00001000| 67 65 2d 4b 75 74 74 61 | 20 6d 65 74 68 6f 64 20 |ge-Kutta| method |
|00001010| 2a 2f 0a 2f 2a 20 61 6e | 6f 74 68 65 72 20 76 61 |*/./* an|other va|
|00001020| 72 69 61 6e 74 20 2a 2f | 0a 64 6f 75 62 6c 65 20 |riant */|.double |
|00001030| 72 6b 34 5f 76 61 72 28 | 66 2c 74 2c 78 2c 68 29 |rk4_var(|f,t,x,h)|
|00001040| 0a 64 6f 75 62 6c 65 20 | 74 2c 20 68 3b 0a 56 45 |.double |t, h;.VE|
|00001050| 43 20 20 20 20 2a 28 2a | 66 29 28 29 2c 20 2a 78 |C *(*|f)(), *x|
|00001060| 3b 0a 7b 0a 20 20 20 73 | 74 61 74 69 63 20 56 45 |;.{. s|tatic VE|
|00001070| 43 20 2a 76 31 2c 20 2a | 76 32 2c 20 2a 76 33 2c |C *v1, *|v2, *v3,|
|00001080| 20 2a 76 34 2c 20 2a 74 | 65 6d 70 3b 0a 20 20 20 | *v4, *t|emp;. |
|00001090| 0a 20 20 20 2f 2a 20 64 | 6f 20 6e 6f 74 20 77 6f |. /* d|o not wo|
|000010a0| 72 6b 20 77 69 74 68 20 | 4e 55 4c 4c 20 69 6e 69 |rk with |NULL ini|
|000010b0| 74 69 61 6c 20 76 65 63 | 74 6f 72 20 2a 2f 0a 20 |tial vec|tor */. |
|000010c0| 20 20 69 66 20 28 20 78 | 20 3d 3d 20 56 4e 55 4c | if ( x| == VNUL|
|000010d0| 4c 20 29 20 20 20 20 20 | 20 20 20 65 72 72 6f 72 |L ) | error|
|000010e0| 28 45 5f 4e 55 4c 4c 2c | 22 72 6b 34 22 29 3b 0a |(E_NULL,|"rk4");.|
|000010f0| 20 20 20 0a 20 20 20 2f | 2a 20 65 6e 73 75 72 65 | . /|* ensure|
|00001100| 20 74 68 61 74 20 76 31 | 2c 20 2e 2e 2e 2c 20 76 | that v1|, ..., v|
|00001110| 34 2c 20 74 65 6d 70 20 | 61 72 65 20 6f 66 20 74 |4, temp |are of t|
|00001120| 68 65 20 63 6f 72 72 65 | 63 74 20 73 69 7a 65 20 |he corre|ct size |
|00001130| 2a 2f 0a 20 20 20 76 5f | 72 65 73 69 7a 65 5f 76 |*/. v_|resize_v|
|00001140| 61 72 73 28 78 2d 3e 64 | 69 6d 2c 20 26 76 31 2c |ars(x->d|im, &v1,|
|00001150| 20 26 76 32 2c 20 26 76 | 33 2c 20 26 76 34 2c 20 | &v2, &v|3, &v4, |
|00001160| 26 74 65 6d 70 2c 20 4e | 55 4c 4c 29 3b 0a 0a 20 |&temp, N|ULL);.. |
|00001170| 20 20 2f 2a 20 72 65 67 | 69 73 74 65 72 20 77 6f | /* reg|ister wo|
|00001180| 72 6b 73 70 61 63 65 20 | 76 61 72 69 61 62 6c 65 |rkspace |variable|
|00001190| 73 20 2a 2f 0a 20 20 20 | 6d 65 6d 5f 73 74 61 74 |s */. |mem_stat|
|000011a0| 5f 72 65 67 5f 76 61 72 | 73 28 30 2c 20 54 59 50 |_reg_var|s(0, TYP|
|000011b0| 45 5f 56 45 43 2c 20 26 | 76 31 2c 20 26 76 32 2c |E_VEC, &|v1, &v2,|
|000011c0| 20 26 76 33 2c 20 26 76 | 34 2c 20 26 74 65 6d 70 | &v3, &v|4, &temp|
|000011d0| 2c 20 4e 55 4c 4c 29 3b | 0a 20 20 20 2f 2a 20 65 |, NULL);|. /* e|
|000011e0| 6e 64 20 6f 66 20 6d 65 | 6d 6f 72 79 20 61 6c 6c |nd of me|mory all|
|000011f0| 6f 63 61 74 69 6f 6e 20 | 2a 2f 0a 0a 20 20 20 28 |ocation |*/.. (|
|00001200| 2a 66 29 28 74 2c 78 2c | 76 31 29 3b 20 20 20 20 |*f)(t,x,|v1); |
|00001210| 20 20 20 20 20 20 20 20 | 20 76 5f 6d 6c 74 61 64 | | v_mltad|
|00001220| 64 28 78 2c 76 31 2c 30 | 2e 35 2a 68 2c 74 65 6d |d(x,v1,0|.5*h,tem|
|00001230| 70 29 3b 0a 20 20 20 28 | 2a 66 29 28 74 2b 30 2e |p);. (|*f)(t+0.|
|00001240| 35 2a 68 2c 74 65 6d 70 | 2c 76 32 29 3b 20 20 20 |5*h,temp|,v2); |
|00001250| 20 76 5f 6d 6c 74 61 64 | 64 28 78 2c 76 32 2c 30 | v_mltad|d(x,v2,0|
|00001260| 2e 35 2a 68 2c 74 65 6d | 70 29 3b 0a 20 20 20 28 |.5*h,tem|p);. (|
|00001270| 2a 66 29 28 74 2b 30 2e | 35 2a 68 2c 74 65 6d 70 |*f)(t+0.|5*h,temp|
|00001280| 2c 76 33 29 3b 20 20 20 | 20 76 5f 6d 6c 74 61 64 |,v3); | v_mltad|
|00001290| 64 28 78 2c 76 33 2c 68 | 2c 74 65 6d 70 29 3b 0a |d(x,v3,h|,temp);.|
|000012a0| 20 20 20 28 2a 66 29 28 | 74 2b 68 2c 74 65 6d 70 | (*f)(|t+h,temp|
|000012b0| 2c 76 34 29 3b 0a 20 20 | 20 0a 20 20 20 2f 2a 20 |,v4);. | . /* |
|000012c0| 6e 6f 77 20 61 64 64 3a | 20 74 65 6d 70 20 3d 20 |now add:| temp = |
|000012d0| 76 31 2b 32 2a 76 32 2b | 32 2a 76 33 2b 76 34 20 |v1+2*v2+|2*v3+v4 |
|000012e0| 2a 2f 0a 20 20 20 76 5f | 6c 69 6e 6c 69 73 74 28 |*/. v_|linlist(|
|000012f0| 74 65 6d 70 2c 20 76 31 | 2c 20 31 2e 30 2c 20 76 |temp, v1|, 1.0, v|
|00001300| 32 2c 20 32 2e 30 2c 20 | 76 33 2c 20 32 2e 30 2c |2, 2.0, |v3, 2.0,|
|00001310| 20 76 34 2c 20 31 2e 30 | 2c 20 56 4e 55 4c 4c 29 | v4, 1.0|, VNULL)|
|00001320| 3b 0a 20 20 20 2f 2a 20 | 61 64 6a 75 73 74 20 78 |;. /* |adjust x|
|00001330| 20 2a 2f 0a 20 20 20 76 | 5f 6d 6c 74 61 64 64 28 | */. v|_mltadd(|
|00001340| 78 2c 74 65 6d 70 2c 68 | 2f 36 2e 30 2c 78 29 3b |x,temp,h|/6.0,x);|
|00001350| 20 20 20 20 20 2f 2a 20 | 78 20 3d 20 78 2b 28 68 | /* |x = x+(h|
|00001360| 2f 36 29 2a 74 65 6d 70 | 20 2a 2f 0a 20 20 20 0a |/6)*temp| */. .|
|00001370| 20 20 20 72 65 74 75 72 | 6e 20 74 2b 68 3b 20 20 | retur|n t+h; |
|00001380| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001390| 20 2f 2a 20 72 65 74 75 | 72 6e 20 74 68 65 20 6e | /* retu|rn the n|
|000013a0| 65 77 20 74 69 6d 65 20 | 2a 2f 0a 7d 0a 0a 0a 2f |ew time |*/.}.../|
|000013b0| 2a 20 66 20 2d 2d 20 72 | 69 67 68 74 2d 68 61 6e |* f -- r|ight-han|
|000013c0| 64 20 73 69 64 65 20 6f | 66 20 4f 44 45 20 73 6f |d side o|f ODE so|
|000013d0| 6c 76 65 72 20 2a 2f 0a | 56 45 43 09 2a 66 28 74 |lver */.|VEC.*f(t|
|000013e0| 2c 78 2c 6f 75 74 29 0a | 56 45 43 09 2a 78 2c 20 |,x,out).|VEC.*x, |
|000013f0| 2a 6f 75 74 3b 0a 64 6f | 75 62 6c 65 09 74 3b 0a |*out;.do|uble.t;.|
|00001400| 7b 0a 20 20 20 69 66 20 | 28 20 78 20 3d 3d 20 56 |{. if |( x == V|
|00001410| 4e 55 4c 4c 20 7c 7c 20 | 6f 75 74 20 3d 3d 20 56 |NULL || |out == V|
|00001420| 4e 55 4c 4c 20 29 0a 20 | 20 20 20 20 65 72 72 6f |NULL ). | erro|
|00001430| 72 28 45 5f 4e 55 4c 4c | 2c 22 66 22 29 3b 0a 20 |r(E_NULL|,"f");. |
|00001440| 20 20 69 66 20 28 20 78 | 2d 3e 64 69 6d 20 21 3d | if ( x|->dim !=|
|00001450| 20 32 20 7c | | 2 | | |
+--------+-------------------------+-------------------------+--------+--------+