Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

☑ This topic is **solved**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-13-2023 03:38 AM
(1377 views)

Hello,

I use Proc IML function in SAS Studio for matrix exponential and the procedure is successful. But when I import the matrix in Excel and call matrix exponential function the results are different from the results from SAS. Is there anybody familiar in the method behind the procedure for matrix exponential both Excel and SAS?

I use Proc IML function in SAS Studio for matrix exponential and the procedure is successful. But when I import the matrix in Excel and call matrix exponential function the results are different from the results from SAS. Is there anybody familiar in the method behind the procedure for matrix exponential both Excel and SAS?

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Please would you show us the syntax you are using both in IML and in EXCEL?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

SAS Studio

PROC IML;

A={1 1, 0 0};

t=2;

X=ExpMatrix (T*A);

ExactAnswer = ( exp (t) | | t* exp(t) ) //

( 0 | | exp (t) );

Print X, ExactAnswer;

Run;

Sorry , the excel VBA macros I can not provide now.

PROC IML;

A={1 1, 0 0};

t=2;

X=ExpMatrix (T*A);

ExactAnswer = ( exp (t) | | t* exp(t) ) //

( 0 | | exp (t) );

Print X, ExactAnswer;

Run;

Sorry , the excel VBA macros I can not provide now.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks for your comments! I appreciate your support!

**SAS Innovate 2025** is scheduled for May 6-9 in Orlando, FL. Sign up to be **first to learn** about the agenda and registration!

Multiple Linear Regression in SAS

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.