Here are a few comments:
1. Your ExactAnswer computation is wrong. It looks like you copied the documentation example but then changed the matrix. The doc says, "For the matrix used in the example...," but you are not using the matrix in the example.
2. I do not know how Excel implements the matrix exponential, but the computation is notoriously difficult. Two excellent numerical analysts (Moler and van Loan) published a famous paper titled, "Nineteen dubious ways to compute the exponential of a matrix."
3. The EXPMATRIX function in IML uses a Pade approximation (reference in doc). For a 2x2 matrix, you can check the computation by applying Putzer's 2x2 formula for the matrix exponential. See p. 866-867 of Gustafson (2022) Differential Equations and Linear Algebra
The following IML program implements the 2x2 case for real eigenvalues:
proc iml;
A={1 1,
0 0};
t=2;
/* call the built-in EXPMATRIX module */
expMat=ExpMatrix (t*A);
Print expMat;
/* implement Putzen's 2x2 formula for real eigenvalues */
start Putzen2x2(A, t);
eval = eigval(A);
/* assume eigenvalues are real */
lambda1 = eval[1,1];
lambda2 = eval[2,1];
r1 = exp(lambda1*t);
r2 = (exp(lambda1*t) - exp(lambda2*t))/(lambda1-lambda2);
expAt = r1*I(2) + r2*(A-lambda1*I(2));
return expAt;
finish;
Putzen = Putzen2x2(A, t);
print Putzen;
Both methods report that exp(2*A) is
{7.3890561 6.3890561,
0 1 }
so there is no evidence that the IML computation is not accurate.
Please would you show us the syntax you are using both in IML and in EXCEL?
I don't think I can offer much help. You can see the source code for the function ExpMatrix from the IML library. Look for the library catalog called SASHELP.IML, and then you can double-click on ExpMatrix to view the source, it is possible that you are using a different algorithm in VBA that would account for the differences.
Here are a few comments:
1. Your ExactAnswer computation is wrong. It looks like you copied the documentation example but then changed the matrix. The doc says, "For the matrix used in the example...," but you are not using the matrix in the example.
2. I do not know how Excel implements the matrix exponential, but the computation is notoriously difficult. Two excellent numerical analysts (Moler and van Loan) published a famous paper titled, "Nineteen dubious ways to compute the exponential of a matrix."
3. The EXPMATRIX function in IML uses a Pade approximation (reference in doc). For a 2x2 matrix, you can check the computation by applying Putzer's 2x2 formula for the matrix exponential. See p. 866-867 of Gustafson (2022) Differential Equations and Linear Algebra
The following IML program implements the 2x2 case for real eigenvalues:
proc iml;
A={1 1,
0 0};
t=2;
/* call the built-in EXPMATRIX module */
expMat=ExpMatrix (t*A);
Print expMat;
/* implement Putzen's 2x2 formula for real eigenvalues */
start Putzen2x2(A, t);
eval = eigval(A);
/* assume eigenvalues are real */
lambda1 = eval[1,1];
lambda2 = eval[2,1];
r1 = exp(lambda1*t);
r2 = (exp(lambda1*t) - exp(lambda2*t))/(lambda1-lambda2);
expAt = r1*I(2) + r2*(A-lambda1*I(2));
return expAt;
finish;
Putzen = Putzen2x2(A, t);
print Putzen;
Both methods report that exp(2*A) is
{7.3890561 6.3890561,
0 1 }
so there is no evidence that the IML computation is not accurate.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.