MATLAB TO HP PRIME - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: MATLAB TO HP PRIME (/thread-21024.html) |
MATLAB TO HP PRIME - xavimb26 - 12-21-2023 10:50 AM 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]') RE: MATLAB TO HP PRIME - matalog - 12-21-2023 01:39 PM What have you got so far in your progress to convert the code into HPPPL? RE: MATLAB TO HP PRIME - xavimb26 - 12-21-2023 01:47 PM 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. RE: MATLAB TO HP PRIME - xavimb26 - 12-21-2023 01:49 PM I don't need it asap but I thought I would be nice to ask and learn RE: MATLAB TO HP PRIME - xavimb26 - 12-21-2023 05:47 PM I havent, its my first time programing for my hp prime. If someone could help me out and code that it would be awesome RE: MATLAB TO HP PRIME - twdeckard - 12-21-2023 06:17 PM 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. RE: MATLAB TO HP PRIME - rprosperi - 12-22-2023 01:30 PM 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... RE: MATLAB TO HP PRIME - xavimb26 - 12-22-2023 01:38 PM 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. RE: MATLAB TO HP PRIME - rprosperi - 12-22-2023 01:50 PM 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 RE: MATLAB TO HP PRIME - Dougggg - 12-22-2023 04:02 PM I wonder if chatGPT can right hpprime programs RE: MATLAB TO HP PRIME - twdeckard - 12-23-2023 02:16 AM 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. RE: MATLAB TO HP PRIME - batx27 - 12-25-2023 04:12 AM (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 RE: MATLAB TO HP PRIME - twdeckard - 12-25-2023 06:33 PM 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 ... RE: MATLAB TO HP PRIME - matalog - 12-30-2023 08:15 AM (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. RE: MATLAB TO HP PRIME - Namir - 01-03-2024 12:08 AM (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. 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 RE: MATLAB TO HP PRIME - twdeckard - 01-04-2024 12:14 AM Did the GPT-4 code work? It looked syntactically correct. RE: MATLAB TO HP PRIME - StephenG1CMZ - 01-04-2024 12:12 PM 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? RE: MATLAB TO HP PRIME - MikeSD - 01-04-2024 05:49 PM (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? |