» Goto page 1, 2  Next
I tried to create a program to do Element-wise Matrix Division and multiplication using chatgpt, but I'm getting a few errors can someone help me figure out how to fix it or if anyone knows of a program that can do Element-wise Matrix Division or multiplication.

Here's the code:

Code:
``` ClrHome Disp "MATRIX OPERATIONS" Disp "1: Multiply" Disp "2: Divide" Prompt choice If choice=1 Then     ClrHome     Disp "MATRIX MULTIPLY"     // Define matrices A and B for input     Matr►list([A],A)     Matr►list([B],B)     // Get dimensions of matrices A and B     dim(A)→R1,C1     dim(B)→R2,C2     // Check if matrices have the same dimensions     If R1=R2 and C1=C2     Then         dim(A)→R,C         // Perform element-wise multiplication         For(I,1,R)             For(J,1,C)                 A(I,J)*B(I,J)→temp                 Disp "Result:", temp             End         End     Else         Disp "Matrices have different dimensions"     End End If choice=2 Then     ClrHome     Disp "MATRIX DIVIDE"     // Define matrices G and Q for input     Matr►list([G],G)     Matr►list([Q],Q)     // Get dimensions of matrices G and Q     dim(G)→R1,C1     dim(Q)→R2,C2     // Check if matrices have the same dimensions     If R1=R2 and C1=C2     Then         dim(G)→R,C         // Perform element-wise division         For(I,1,R)             For(J,1,C)                 10fPart(G(I,J)/Q(I,J))→temp  // Limiting to 15 decimal places                 Disp "Result:", temp             End         End     Else         Disp "Matrices have different dimensions"     End End ```
You shouldn't use statistical models like ChatGPT to generate code. It doesn't "know" what it doesn't "know," and as a result it will happily spit out completely nonsensical answers with the exact same confident tone it uses when giving correct answers. This is mildly annoying when you're trying to build something relatively low-stakes and easy to verify like this program, but for larger programs using statistical models to generate code can easily introduce major, hard to track down bugs or even security vulnerabilities.

Numeric variables in TI-BASIC can only be one letter long, and must be an uppercase letter or theta. List names can be up to 4 letters five alphanumeric (plus theta) characters long and must start with the list symbol ʟ (although it can be omitted for assignments). The → operator cannot "destructure" lists into their components - you'll need to store them into another list or Ans and then access items with e.g. Ans(2). Lists can only hold numbers, and cannot be 2D like matrices are. So, Matr►list([G],G) only works if the matrix only has a single column. List comparisons operate element-wise, but If only accepts numeric values, so you'll need to take min() of the result of the comparison to check if the entire list matches.

Combining these together, you can do something like this:

Code:
```ClrHome Disp "MATRIX OPERATIONS" Disp "1: Multiply" Disp "2: Divide" Input C 3-2C→E If min(dim([A])≠dim([B] Then Disp "Matrices have different dimensions" Return End dim([A]→dim([C] For(I,1,Ans(1 For(J,1,Ans(2 [A](I,J)([B](I,J))^E→[C](I,J End End [C]```

(edited to replace typo'd } -> ])
Thank you so much the explanation I have never coded in Ti-Basic hence chatGPT I tried run your program, but got an syntax error at this line:
Code:
` If min(dim([A])≠dim([B}`
I tried to fix it by changing that line to this:
Code:
` If min(dim([A])≠dim([B))`

but I still get an undefined error any suggestions on how to fix it?
calcguy55 wrote:
Thank you so much the explanation I have never coded in Ti-Basic hence chatGPT I tried run your program, but got an syntax error at this line:
Code:
` If min(dim([A])≠dim([B}`
I tried to fix it by changing that line to this:
Code:
` If min(dim([A])≠dim([B))`

but I still get an undefined error any suggestions on how to fix it?

The original suggestion had a typo:

Code:
`If min(dim([A])≠dim([B] `

However, it shouldn't really matter, since [A] and [B] refer to the matrix variables, not [ + A + ] in sequence, and grabbing them from [2ND][MATH] will insert the correct token.
Quote:
List names can be up to 4 letters long

Point of order: 5 uppercase alphanumeric + theta characters long, starting with a non-number.

Quote:
You shouldn't use statistical models like ChatGPT to generate code.

Big agree. It pretends to know TI-BASIC, but has no idea what the syntax is, and gives you a weird mash-up of different BASIC-esque languages. May I recommend a good book on the topic?
Anybody have any suggestions on how to fix the code. Anyone know where I can find a program to do element wise matrix division and multiplication
calcguy55 wrote:
Anybody have any suggestions on how to fix the code. Anyone know where I can find a program to do element wise matrix division and multiplication

Did you even read the last few posts? commandblockguy’s code works perfectly fine, so long as you’ve typed it in correctly, adjusted the typo as mentioned, and are using the proper tokens as mentioned; [A] and [B] need to be selected from the matrix menu, and not actually typed out as 3 separate characters. You can access the matrix menu by hitting [2nd] [x^-1] and then hit enter on which matrix token you want to paste into the program.
Michael2_3B wrote:
calcguy55 wrote:
Anybody have any suggestions on how to fix the code. Anyone know where I can find a program to do element wise matrix division and multiplication

Did you even read the last few posts? commandblockguy’s code works perfectly fine, so long as you’ve typed it in correctly, adjusted the typo as mentioned, and are using the proper tokens as mentioned; [A] and [B] need to be selected from the matrix menu, and not actually typed out as 3 separate characters. You can access the matrix menu by hitting [2nd] [x^-1] and then hit enter on which matrix token you want to paste into the program.

Yeah I did I'm just not sure how to include the matrices when I run the program it is before I choose option one or two not really sure how to use the program
You have to create and edit any of the matrices that you need ([A] and [B] in this case) before running the program.

You can do this by going to the matrix menu by hitting [2nd] [x^-1], scrolling to the right to the menu that says “EDIT”, then select a matrix, type in the dimensions you want for the matrix, then go down and enter the data inside of it in the proper locations. To exit this menu, hit [2nd] [mode].

Once you’ve filled out both of your matrices with your data, you can run the program.
Out of curiosity, what do you need this program for?
commandblockguy wrote:
Out of curiosity, what do you need this program for?

I'm working with 8x8 matrices and I have to perform element wide calculations and I don't want to do it by hand.

I got your program to run, but the resulting matrix C was not correct. Given these two matrices:

Code:
``` A = [495, 288, 198, 80, 56, 20, 3, 1;      356, 233, 180, 76, 32, 12, 8, 2;      198, 201, 309, 43, 33, 10, 6, 2;      99, 56, 43, 21, 19, 8, 3, 2;      16, 8, 10, 12, 11, 5, 2, 1;      5, 5, 4, 2, 3, 2, 1, 1;      3, 0, 2, 2, 1, 1, 2, 0;      1, 1, 3, 0, 2, 1, 1, 1]; ```

Code:
``` B = [16, 11, 10, 16, 24, 40, 51, 61;      12, 12, 14, 19, 26, 58, 60, 55;      14, 13, 16, 24, 40, 57, 69, 56;      14, 17, 22, 29, 51, 87, 80, 62;      18, 22, 37, 56, 68, 109, 103, 77;      24, 35, 55, 64, 81, 104, 113, 92;      49, 64, 78, 87, 103, 121, 120, 101;      72, 92, 95, 98, 112, 100, 103, 99]; ```

I want to get this as the result in matrix C:

I also need all the values in C to be rounded to the nearest integer

Code:
```ClrHome Disp "MATRIX OPERATIONS" Disp "1: Multiply" Disp "2: Divide" Input C 3-2C→E If min(dim([A])≠dim([B] Then Disp "Matrices have different dimensions" Return End dim([A]→dim([C] Ans→L1 For(I,1,L1(1 For(J,1,L1(2 [A](I,J)([B](I,J))^E→[C](I,J End End [C]```
commandblockguy wrote:

Code:
```ClrHome Disp "MATRIX OPERATIONS" Disp "1: Multiply" Disp "2: Divide" Input C 3-2C→E If min(dim([A])≠dim([B] Then Disp "Matrices have different dimensions" Return End dim([A]→dim([C] Ans→L1 For(I,1,L1(1 For(J,1,L1(2 [A](I,J)([B](I,J))^E→[C](I,J End End [C]```

I tried this new version the answers are completely off. Thank you for all your help with this btw
It works perfectly fine for me. So long as you’re inputting 1 for multiplication at the prompt, and 2 for division. Entering anything else will give you incorrect results.
Michael2_3B wrote:
It works perfectly fine for me. So long as you’re inputting 1 for multiplication at the prompt, and 2 for division. Entering anything else will give you incorrect results.

Really? just to verify I have both matrices A and B which contain the data I want to multiply or divide.
Then when I run the program either select 1 or 2 and the result should be saved in matrix C right? if it makes a difference I am using the Ti-84 plus
calcguy55 wrote:
Michael2_3B wrote:
It works perfectly fine for me. So long as you’re inputting 1 for multiplication at the prompt, and 2 for division. Entering anything else will give you incorrect results.

Really? just to verify I have both matrices A and B which contain the data I want to multiply or divide.
Then when I run the program either select 1 or 2 and the result should be saved in matrix C right? if it makes a difference I am using the Ti-84 plus

Calculator should not matter in this case. Can you show us what you are getting if not the desired output?
As kg583 said please show us what you are getting as a result. And if possible, please show us the code you have EXACTLY as it appears on your calculator.
Michael2_3B wrote:
As kg583 said please show us what you are getting as a result. And if possible, please show us the code you have EXACTLY as it appears on your calculator.

The result I get is a matrix of all zeros. I checked my calculator the code is correct. Does it matter that copied and pasted the code into ti connect CE made a new program and transferred that file to my calculator. Here's the file
The L1 in my code is supposed to be the L1 token (2nd + 1), not the letter L followed by the number 1.
commandblockguy wrote:
The L1 in my code is supposed to be the L1 token (2nd + 1), not the letter L followed by the number 1.
I just copied and pasted the code you posted I'm not sure how to edit L1 to be L1 token (2nd + 1).

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» Goto page 1, 2  Next
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum