Runge-Kutta method: Difference between revisions
Content deleted Content added
added Haskell |
→{{header|J}}: edit alternative version for clarity |
||
Line 338: | Line 338: | ||
10 676 _5.09833e_5</lang> |
10 676 _5.09833e_5</lang> |
||
Alternative |
'''Alternative solution:''' |
||
⚫ | |||
The following solution replaces the for loop as well as the calculation of the increments (ks) with an accumulating suffix. |
|||
⚫ | |||
: |
: |
||
tableau=. 1 0.5 0.5, x * u y |
|||
ks=. (x * [: u y + (* x&,))/\. tableau |
|||
({:y) + 6 %~ +/ 1 2 2 1 * ks |
|||
) |
) |
||
rk4=: |
rk4=: adverb define |
||
'Y0 a b h'=. 4{. y |
'Y0 a b h'=. 4{. y |
||
T=. a + i.@>:&.(%&h) b-a |
|||
(,. [: h&(u nextY)@,/\. Y0 ,~ }.)&.|. T |
|||
)</lang> |
)</lang> |
||