EXPMATX.OMS
Script File:
# Description
# Uses matrix exponential to compute sine and cosine functions.
#
clear
# coefficient matrix for dy / dt = A * y
A = { [ 0., 10. ] , [ - 10., 0. ] }
# matrix exponential of A
E = expmat(A, 1e-4, 6)
# value of y(1) = sin(10 * t) and
# y(2) = cos(10 * t) at t = 0.
y = {0., 1.}
# format for output
format real "f10.5"
# header for output
header = "t, sin(10 * t), cos(10 * t), y(1), y(2)"
header = align(header, ", ", [10, 11, 11, 11, 11])
write("screen", header)
for i = 1 to 10 begin
# value of time
t = real(i)
# value of y using matrix exponential
y = E * y
#
write("screen", [t, sin(10 * t), cos(10 * t), y'])
end
Output:
t sin(10 * t) cos(10
1.00000 -0.54402 -0.83907 -0.54402 -0.83907
2.00000 0.91295 0.40808 0.91295 0.40808
3.00000 -0.98803 0.15425 -0.98803 0.15425
4.00000 0.74511 -0.66694 0.74511 -0.66694
5.00000 -0.26237 0.96497 -0.26237 0.96497
6.00000 -0.30481 -0.95241 -0.30481 -0.95241
7.00000 0.77389 0.63332 0.77389 0.63332
8.00000 -0.99389 -0.11039 -0.99389 -0.11038
9.00000 0.89400 -0.44807 0.89400 -0.44808
10.00000 -0.50637 0.86232 -0.50636 0.86232