Usage Note 22779: Solve a system of n equations in n unknowns
To solve for the unknowns in a system of linear or nonlinear equations, use the SOLVE statement in the MODEL procedure. You must have exactly n equations in order to solve for n unknowns or the system cannot be solved. You can specify the equations in either normalized form or in the general form using the eq. prefix. The DATA= input data set should contain the unknown variables to be solved for, as well as any other exogenous variables that appear in the equations, if any. The values supplied for the unknown variables in the input data set will be used as starting values. If you do not have starting values, you can set all the unknowns as missing values in the input data set. The default starting value of 0.0001 is used for any unknown variable if its value is missing in the input data set.
The following example illustrates how to solve for two unknowns in two nonlinear equations, where the equations are as follows:
x1 + x2 - x1*x2 + 2 = 0
x1 * exp(-x2) - 1 = 0
The following DATA step supplies initial values for the unknowns.
data init;
x1=.2;
x2=-2;
run;
The following PROC MODEL step specifies the two equations in general form using the eq. prefix, and a SOLVE statement then solves for the unknowns and saves them in data set Solved. The solution is displayed by the PRINT procedure.
proc model data=init;
eq.one = x1 + x2 - x1*x2 + 2;
eq.two = x1 * exp(-x2) - 1;
solve x1 x2 / out=Solved ;
run;
proc print data=Solved noobs;
var x1 x2;
run;
Sometimes the equations are given in normalized form. For example, here are the above equations in normalized form:
x2 = (x1+2)/(x1-1)
x1 = 1/exp(-x2)
You can specify the equations in normalized form in PROC MODEL. The solution is the same as above.
proc model data=init;
x2 = (x1+2)/(x1-1);
x1 = 1/exp(-x2) ;
solve x1 x2 / out=Solved2;
run;
proc print data=Solved2 noobs;
var x1 x2;
run;
Operating System and Release Information
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
Type: | Usage Note |
Priority: | low |
Topic: | SAS Reference ==> Procedures ==> MODEL Analytics Analytics ==> Forecasting Analytics ==> Simulation Analytics ==> Time Series Analysis
|
Date Modified: | 2020-04-17 17:55:49 |
Date Created: | 2002-12-16 10:56:36 |