Post Reply 
MATLAB TO HP PRIME
12-21-2023, 10:50 AM
Post: #1
MATLAB TO HP PRIME
Can someone help me to turn this matlab code into an hp prime program code? It's a single iteration of simplex:

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]

B = A(:,base0)
cb = C(base0)
xb = B\b
z0 = cb*xb
cn = C; cn(base0) = []
N = A; N(:,base0) = []

cnred = cn - cb*inv(B)*N

restrict = xb./(inv(B)*N*[0 0 0 0 1]')
Find all posts by this user
Quote this message in a reply
12-21-2023, 01:39 PM
Post: #2
RE: MATLAB TO HP PRIME
What have you got so far in your progress to convert the code into HPPPL?
Find all posts by this user
Quote this message in a reply
12-21-2023, 01:47 PM
Post: #3
RE: MATLAB TO HP PRIME
The things is that I'm new in HP prime programing and I needed help because I don't know anything and needed this simple program to just have it in my HP Prime and not having to pull my laptop. It would be so nice if someone could help. Smile
Find all posts by this user
Quote this message in a reply
12-21-2023, 01:49 PM
Post: #4
RE: MATLAB TO HP PRIME
I don't need it asap but I thought I would be nice to ask and learn
Find all posts by this user
Quote this message in a reply
12-21-2023, 05:47 PM
Post: #5
RE: MATLAB TO HP PRIME
I havent, its my first time programing for my hp prime. If someone could help me out and code that it would be awesome
Find all posts by this user
Quote this message in a reply
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
12-22-2023, 01:30 PM
Post: #7
RE: MATLAB TO HP PRIME
You have to understand the near-lack of replies here...

It sounds like you have been given a homework assignment and rather than actually putting some effort into trying to solve it, you've simply instead asked someone... anyone... here to do it for you, without putting any effort in at all...

That analysis may be completely wrong, but your challenge is to motivate assistance by explaining why the above perception is wrong and why folks should help out if you're unwilling to even try a little...

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
12-22-2023, 01:38 PM
Post: #8
RE: MATLAB TO HP PRIME
I don't understand why you're so negative. I haven't been given any homework or nothing, I've programed this in Matlab and I thought it would be great to try and have it in my HP prime, but after trying and failing more than I wanted I decided to ask for help in a forum where people help other people that's it.
Find all posts by this user
Quote this message in a reply
12-22-2023, 01:50 PM
Post: #9
RE: MATLAB TO HP PRIME
I'm not being negative, only trying to help you understand how your request feels, at least here... new members post such requests all the time, and I thought it may help to understand which type do, and do not, get helpful replies. I also could have simply ignored it, like the 200+ other readers have,

If the situation I described is inaccurate, I suggest you explain enough to motivate people to help out, when you aren't willing to share your own efforts. In other words, motivate people here to help you learn, rather than to simply do your bidding.

Feel free to take or ignore my advice, it's up to you.

Merry Christmas

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
12-22-2023, 04:02 PM
Post: #10
RE: MATLAB TO HP PRIME
I wonder if chatGPT can right hpprime programs
Find all posts by this user
Quote this message in a reply
12-23-2023, 02:16 AM
Post: #11
RE: MATLAB TO HP PRIME
It understands the syntax and handled a range of basic examples. It is interesting because I doubt there are many examples in its training corpus. I doubt there is a lot of PPL in git.

Amazing that I am still toying with a 600 khz HP 41cx with 2kilobytes of RAM and using a large neuronal model with 1.8 trillion weights and biases that may be the harbinger of one of the biggest revolutions in technological history to suggest program snippets.

I would have never imagined.
Find all posts by this user
Quote this message in a reply
12-25-2023, 04:12 AM
Post: #12
RE: MATLAB TO HP PRIME
(12-22-2023 04:02 PM)Dougggg Wrote:  I wonder if chatGPT can right hpprime programs

Yeah I wouldn't even try that. Chatgpt can't even write a simple quadratic formula program in Ti-Basic without syntax errors
Find all posts by this user
Quote this message in a reply
12-25-2023, 06:33 PM
Post: #13
RE: MATLAB TO HP PRIME
are there any errors in the MATLAB port I posted?

Which model version have you tried most recently? I asked for a TI basic quadratic program from GPT-4 and cannot discern any errors.

The rate at which the foundational models are improving is mind blowing.

GPT-4 will author and exdcute its own python when confronted with a complex document parsing problem.

The times they are a changin ...
Find all posts by this user
Quote this message in a reply
12-30-2023, 08:15 AM
Post: #14
RE: MATLAB TO HP PRIME
(12-22-2023 01:38 PM)xavimb26 Wrote:  I don't understand why you're so negative. I haven't been given any homework or nothing, I've programed this in Matlab and I thought it would be great to try and have it in my HP prime, but after trying and failing more than I wanted I decided to ask for help in a forum where people help other people that's it.

I have asked you above, and I'll ask again. What have you tried so far to convert this yourself?

Did you look at the manual to try to convert the input of variables or the other commands?

If you had have shown some of your own work towards the answer then I would have helped you with the rest.
Find all posts by this user
Quote this message in a reply
01-03-2024, 12:08 AM
Post: #15
RE: MATLAB TO HP PRIME
(12-21-2023 01:47 PM)xavimb26 Wrote:  The things is that I'm new in HP prime programing and I needed help because I don't know anything and needed this simple program to just have it in my HP Prime and not having to pull my laptop. It would be so nice if someone could help. Smile

You are asking for a tall order. I use Matlabb on a daily basis and it is very different from the HP-Prime programming language. Stick with your laptop and you will save yourself hours and hours (and hours) of translating and very painfull debugging on the Prime.

Namir
Find all posts by this user
Quote this message in a reply
01-04-2024, 12:14 AM
Post: #16
RE: MATLAB TO HP PRIME
Did the GPT-4 code work? It looked syntactically correct.
Find all posts by this user
Quote this message in a reply
01-04-2024, 12:12 PM (This post was last modified: 01-04-2024 05:45 PM by StephenG1CMZ.)
Post: #17
RE: MATLAB TO HP PRIME
That surprised me.

A quick visual inspection shows what looks like a single unpaired quote (') or apostrophe on the last line (restrict :=), which certainly looks dubious, though I haven't checked that line's syntax. (It looks identical to the MATLAB original - what is its function in MATLAB?).

I get syntax errors on the first few lines, on the A line as-is, or on the lower case b if i embed it in an EXPORT functionname()BEGIN...END.

(Note: My HP Prime might be outdated as it only runs on an old Android 8: hp 2021 0514)

Update: It seems in MATLAB that unpaired ' might be a complex transpose, not a typo?
Does that work in PPL?

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
01-04-2024, 05:49 PM
Post: #18
RE: MATLAB TO HP PRIME
(12-22-2023 01:38 PM)xavimb26 Wrote:  I don't understand why you're so negative. I haven't been given any homework or nothing, I've programed this in Matlab and I thought it would be great to try and have it in my HP prime, but after trying and failing more than I wanted I decided to ask for help in a forum where people help other people that's it.

You say you've tried, then why not show what you have tried? it might be easer for readers to make a simple corection to an error, than doing all the work for you.

Do you have examples of what you have tried?
Find all posts by this user
Quote this message in a reply
Post Reply 




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