turn on suggestions

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

Showing results for

- JMP User Community
- :
- Discussions
- :
- How to solve two variables (P and T) iteratively (...

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 4:23 AM
(716 views)

Good day.

I am new to the JMP and JSL. I have used SAS and I am trying to consolidate some of the work I did in SAS into JMP.

I this case, I have some SAS code (included below) that solves two variables, P (pressure) and T (temperature), iteratively using the equations below.

What is the easiest way to do this JMP (and JSL).

Many thanks in advance.

Rob Preston (grateful novice JMP user)

############################################################################################################

**code from SAS (v9.1)

*solve P, T iteratively, note LOG is LN (excl K);

P_est=0.0;

TK=0.0;

T=400;

T_est=T+273;

TDIFF=10.0;

IT=0;

DO UNTIL (TDIFF<3.0);

IT=IT+1;

P_est=((-T_est/126.9)*log(aCrCaTs))+(15.483*(log(Crno/T_est)))+(T_est/71.38)+107.8;

TK=(23166+39.28*P_est)/(13.25+15.35*Ti+4.5*Fe-1.55*(Al+Cr-Na)+(LOG(aEn))**2);

*to ensure convergence (set at within 3C);

TDIFF = ABS(TK-T_EST);

if TDIFF > 0 then T_est = TK+1;

else if TDIFF < 0 then T_est=TK-1;

else T_est=TK;

END;

############################################################################################################

2 ACCEPTED SOLUTIONS

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 5:24 AM
(1410 views)

Solution

Here is your SAS code converted to JMP. What I am assuming is that what you provided is a data step that has a data table behind it, and that the code you provided is processed for each row in the data table. Also, that the cariables mentioned, aCrCaTs, Crno, Fe etc. are columns in the data table

```
Names Default To Here( 1 );
dt = Current Data Table();
For Each Row(
P_est = 0.0;
TK = 0.0;
T = 400;
T_est = T + 273;
TDIFF = 10.0;
IT = 0;
While( TDIFF >= 3.0,
IT = IT + 1;
P_est = ((-T_est / 126.9) * Log( :aCrCaTs )) + (15.483 * (Log( :Crno / T_est ))) + (T_est / 71.38) + 107.8;
TK = (23166 + 39.28 * P_est) / (13.25 + 15.35 * Ti + 4.5 * :Fe - 1.55 * (:Al + :Cr - :Na) + (Log( :aEn )) ^ 2);
//to ensure convergence (set at within 3C);
TDIFF = Abs( TK - T_EST );
If(
TDIFF > 0, T_est = TK + 1,
TDIFF < 0, T_est = TK - 1,
T_est = TK
);
);
);
```

Jim

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 6:05 AM
(1393 views)

Solution

I had a different take on your problem than Jim. I didn't realize that the independent variables were in the same row and you want to determine P and T for every row. If that is so, then his solution (translation of your SAS code) should be helpful.

My take was that the independent variables (e.g., aCrCaTs) were determined in the code prior to the determination of P and T. I don't have those values so I can't test it but my take was to try the Minimize() function I mentioned earlier. (Actually, if it works for any set of variables, then it could be applied row-wise through the For Each Row() function as well.) Here is my (speculative) solution to find P and T:

```
// initialize variables
T = 400;
T_est = T + 273;
aCrCaTs = ?;
Cmo = ?;
Ti = ?;
Fe = ?;
Al = ?;
Cr = ?;
Na = ?;
aEn = ?;
// estimate P and T
Minimize(
P_est = ((-T_est/1269)*Log(aCrCaTs)) + (15.483*(Log(Cmo/T_est))) + (T_est/71.38)+107.8;
TK = (23166+39.28*P_est) / (13.25+15.35*Ti+4.5*Fe-1.55*(Al+Cr+Na)+Log(aEn)^2);
Abs( TK - T_est),
{ P_est, TK },
<< Max Iter( 100 ),
<< Tolerance( 3.0 )
);
```

The first argument is the expression to be minimized. In this case, the glue operator will return the absolute difference, which is the quantity that you want to minimize. The second argument is a list of the parameters to be determined. The optional messages can be used to exercise further control on the numerical search.

So now you have at least two ways to accomplish your task in JMP.

Learn it once, use it forever!

6 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 5:08 AM
(711 views)

You can probably use the **Maximize()** or **Minimize()** functions. See **Help** > **Scripting Index** > **Functions** as well as **Help** > **Book** > **Scripting Guide** for information about these two functions.

I am not sure that you need a code solution, though. Instead, consider using the **Nonlinear** platform. We generally perceive it as a way to fit non-linear models but it is actually a general maximization solution, too. See **Help** > **Books** > **Predictive and Specialized Modeling**, Chapter 13, "Nonlinear Regression," for more information.

Of course, you can also script this platform, if necessary, but it is a great solver.

Learn it once, use it forever!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 5:13 AM
(709 views)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 5:24 AM
(1411 views)

Here is your SAS code converted to JMP. What I am assuming is that what you provided is a data step that has a data table behind it, and that the code you provided is processed for each row in the data table. Also, that the cariables mentioned, aCrCaTs, Crno, Fe etc. are columns in the data table

```
Names Default To Here( 1 );
dt = Current Data Table();
For Each Row(
P_est = 0.0;
TK = 0.0;
T = 400;
T_est = T + 273;
TDIFF = 10.0;
IT = 0;
While( TDIFF >= 3.0,
IT = IT + 1;
P_est = ((-T_est / 126.9) * Log( :aCrCaTs )) + (15.483 * (Log( :Crno / T_est ))) + (T_est / 71.38) + 107.8;
TK = (23166 + 39.28 * P_est) / (13.25 + 15.35 * Ti + 4.5 * :Fe - 1.55 * (:Al + :Cr - :Na) + (Log( :aEn )) ^ 2);
//to ensure convergence (set at within 3C);
TDIFF = Abs( TK - T_EST );
If(
TDIFF > 0, T_est = TK + 1,
TDIFF < 0, T_est = TK - 1,
T_est = TK
);
);
);
```

Jim

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 5:31 AM
(704 views)

Yes, you assumptions are correct. I have scripted all the calculations for the variables that are referred to in the equations. So that's all sorted.

Thank you very much for your assistance. Greatly appreciated!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 6:05 AM
(1394 views)

I had a different take on your problem than Jim. I didn't realize that the independent variables were in the same row and you want to determine P and T for every row. If that is so, then his solution (translation of your SAS code) should be helpful.

My take was that the independent variables (e.g., aCrCaTs) were determined in the code prior to the determination of P and T. I don't have those values so I can't test it but my take was to try the Minimize() function I mentioned earlier. (Actually, if it works for any set of variables, then it could be applied row-wise through the For Each Row() function as well.) Here is my (speculative) solution to find P and T:

```
// initialize variables
T = 400;
T_est = T + 273;
aCrCaTs = ?;
Cmo = ?;
Ti = ?;
Fe = ?;
Al = ?;
Cr = ?;
Na = ?;
aEn = ?;
// estimate P and T
Minimize(
P_est = ((-T_est/1269)*Log(aCrCaTs)) + (15.483*(Log(Cmo/T_est))) + (T_est/71.38)+107.8;
TK = (23166+39.28*P_est) / (13.25+15.35*Ti+4.5*Fe-1.55*(Al+Cr+Na)+Log(aEn)^2);
Abs( TK - T_est),
{ P_est, TK },
<< Max Iter( 100 ),
<< Tolerance( 3.0 )
);
```

The first argument is the expression to be minimized. In this case, the glue operator will return the absolute difference, which is the quantity that you want to minimize. The second argument is a list of the parameters to be determined. The optional messages can be used to exercise further control on the numerical search.

So now you have at least two ways to accomplish your task in JMP.

Learn it once, use it forever!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 6:18 AM
(694 views)

I am going to try out both methods. This is a great learning exercise for me!