mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   PARI/GP (https://www.mersenneforum.org/forumdisplay.php?f=155)
-   -   PARI's commands (https://www.mersenneforum.org/showthread.php?t=13636)

science_man_88 2010-08-31 17:30

[QUOTE=CRGreathouse;227882]With
[code]M=[1,2;3,4][/code]
you can use
[code]M[2,1][/code]
to show the element in the second row, first column.[/QUOTE]

that isn't quite what I wanted I figure it out though now I can make a multiplication table lol.

science_man_88 2010-08-31 17:41

maybe not lol I can't get one thing to work lol if I could I can generate a multiplication table.

CRGreathouse 2010-08-31 18:33

[QUOTE=science_man_88;227921]that isn't quite what I wanted[/QUOTE]

That's the difficulty, isn't it -- I can only know what you write, not what you want.

[QUOTE=science_man_88;227926]maybe not lol I can't get one thing to work lol if I could I can generate a multiplication table.[/QUOTE]

[code]for(x=1,9,for(y=1,9,print1(x*y" "));print())[/code]
does a rough job. You'll have to work a bit more to get the columns to line up.

science_man_88 2010-08-31 18:48

well I was going to try to use matrices to do it but:

[CODE]multiplication(i,j)= x=Mat([]);for(i=1,i,for(j=1,j,x(i,j)=i*j));return(x(i,j))[/CODE]

was the best I could do I think

CRGreathouse 2010-08-31 18:50

Use [] for accessing the elements of vectors and matrices, not ().

I'm not sure why you're using one here, though. You fill in a multiplication table, pull out one element, throw the table away, then return the one element.

3.14159 2010-08-31 20:04

Well, I'm finishing up on b = 501-750.

I have 10 values left.

science_man_88 2010-08-31 20:16

[QUOTE=CRGreathouse;227936]Use [] for accessing the elements of vectors and matrices, not ().

I'm not sure why you're using one here, though. You fill in a multiplication table, pull out one element, throw the table away, then return the one element.[/QUOTE]

1) I couldn't get [] to work for matrices
2) I wanted the whole table but I couldn't get it all to print

science_man_88 2010-08-31 20:21

I gave up on matrices.

[CODE]multiplication(i,j=i)= for(i=1,i,for(j=1,j,print1(i*j"\t"));print(""))[/CODE]

CRGreathouse 2010-08-31 20:34

[QUOTE=science_man_88;227950]1) I couldn't get [] to work for matrices[/QUOTE]

You'll need to define the matrix first. You tried -- but you only made it a 0x0 matrix, you need an i x j. try matrix(i,j,unused1, unused2, 0) or even matrix(i,j,x,y,x*y) which avoids the need for the loops.

[QUOTE=science_man_88;227950]2) I wanted the whole table but I couldn't get it all to print[/QUOTE]

Just return the matrix.

[code]foo(i,j)=matrix(i,j,x,y,x*y)[/code]

CRGreathouse 2010-08-31 20:35

[QUOTE=science_man_88;227951]I gave up on matrices.

[CODE]multiplication(i,j=i)= for(i=1,i,for(j=1,j,print1(i*j"\t"));print(""))[/CODE][/QUOTE]

That looks fine, except that your variables are bumping into each other: you have the "max j" and the "loop j" and likewise for i. If you rename them this should work nicely.

science_man_88 2010-08-31 20:39

[QUOTE=CRGreathouse;227952]You'll need to define the matrix first. You tried -- but you only made it a 0x0 matrix, you need an i x j. try matrix(i,j,unused1, unused2, 0) or even matrix(i,j,x,y,x*y) which avoids the need for the loops.



Just return the matrix.

[code]foo(i,j)=matrix(i,j,x,y,x*y)[/code][/QUOTE]

I tried your idea:

[CODE][COLOR="Red"]*** too many arguments: ...[/COLOR]plication(i,j=i)=x=Mat(i,j,x,y,x*y);for(i=1,i
[COLOR="Red"]^--------------------[/COLOR][/CODE]


All times are UTC. The time now is 23:14.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.