Post Reply 
MATLAB TO HP PRIME
12-21-2023, 06:17 PM
Post: #6
RE: MATLAB TO HP PRIME
Here was GPT-4s answer

Translating the MATLAB code into HP PPL (HP Prime Programming Language) requires considering the differences in syntax and functionality between MATLAB and HP PPL. HP PPL is used in HP Prime calculators, which have a different way of handling matrix and vector operations compared to MATLAB. Here's how you can translate the code:

```ppl
// Define matrices and vectors
A := [[8, 10, -9, 9, 7, 1, 0, 0], [4, 9, -8, -10, -7, 0, 1, 0], [8, 1, -4, 5, -8, 0, 0, 1]];
C := [5, 3, 5, 0, -1, 0, 0, 0];
b := [152, 112, 159];
base0 := [1, 3, 7];

// Adjust for one-based indexing
base0 := base0 - 1;

// Extracting B, cb, and solving for xb
B := COLN(A, base0);
cb := ELM(C, base0);
xb := LSQ(B, b);

// Calculate z0
z0 := cb * xb;

// Define cn and N
cn := C;
FOR i FROM SIZE(base0)-1 DOWNTO 0 DO
cn := DEL(cn, base0(i+1) + 1);
END;
N := A;
FOR i FROM SIZE(base0)-1 DOWNTO 0 DO
N := DELCOL(N, base0(i+1) + 1);
END;

// Calculate cnred
cnred := cn - (cb * INV(B) * N);

// Calculate restrict
restrict := xb / (INV(B) * N * [0, 0, 0, 0, 1]');
```

A few notes on this translation:

1. **Indexing**: HP PPL is one-based, so we adjust the `base0` index accordingly.
2. **Matrix and Vector Operations**: Functions like `COLN`, `ELM`, `LSQ`, `DEL`, and `DELCOL` are used to handle matrix operations in HP PPL.
3. **Solving Linear Systems**: `LSQ` is used for solving linear equations.
4. **Matrix Inversion**: `INV` function is used to invert matrices.

Make sure to test this on an actual HP Prime calculator or emulator to ensure compatibility, as there might be differences in the specific version or model of the calculator.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
MATLAB TO HP PRIME - xavimb26 - 12-21-2023, 10:50 AM
RE: MATLAB TO HP PRIME - matalog - 12-21-2023, 01:39 PM
RE: MATLAB TO HP PRIME - xavimb26 - 12-21-2023, 01:47 PM
RE: MATLAB TO HP PRIME - Namir - 01-03-2024, 12:08 AM
RE: MATLAB TO HP PRIME - xavimb26 - 12-21-2023, 01:49 PM
RE: MATLAB TO HP PRIME - xavimb26 - 12-21-2023, 05:47 PM
RE: MATLAB TO HP PRIME - twdeckard - 12-21-2023 06:17 PM
RE: MATLAB TO HP PRIME - rprosperi - 12-22-2023, 01:30 PM
RE: MATLAB TO HP PRIME - xavimb26 - 12-22-2023, 01:38 PM
RE: MATLAB TO HP PRIME - matalog - 12-30-2023, 08:15 AM
RE: MATLAB TO HP PRIME - MikeSD - 01-04-2024, 05:49 PM
RE: MATLAB TO HP PRIME - rprosperi - 12-22-2023, 01:50 PM
RE: MATLAB TO HP PRIME - Dougggg - 12-22-2023, 04:02 PM
RE: MATLAB TO HP PRIME - batx27 - 12-25-2023, 04:12 AM
RE: MATLAB TO HP PRIME - twdeckard - 12-23-2023, 02:16 AM
RE: MATLAB TO HP PRIME - twdeckard - 12-25-2023, 06:33 PM
RE: MATLAB TO HP PRIME - twdeckard - 01-04-2024, 12:14 AM
RE: MATLAB TO HP PRIME - StephenG1CMZ - 01-04-2024, 12:12 PM



User(s) browsing this thread: 1 Guest(s)