mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Computer Science & Computational Number Theory > PARI/GP

Reply
 
Thread Tools
Old 2010-08-31, 17:30   #1255
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
With
Code:
M=[1,2;3,4]
you can use
Code:
M[2,1]
to show the element in the second row, first column.
that isn't quite what I wanted I figure it out though now I can make a multiplication table lol.
science_man_88 is offline   Reply With Quote
Old 2010-08-31, 17:41   #1256
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

maybe not lol I can't get one thing to work lol if I could I can generate a multiplication table.
science_man_88 is offline   Reply With Quote
Old 2010-08-31, 18:33   #1257
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
that isn't quite what I wanted
That's the difficulty, isn't it -- I can only know what you write, not what you want.

Quote:
Originally Posted by science_man_88 View Post
maybe not lol I can't get one thing to work lol if I could I can generate a multiplication table.
Code:
for(x=1,9,for(y=1,9,print1(x*y" "));print())
does a rough job. You'll have to work a bit more to get the columns to line up.
CRGreathouse is offline   Reply With Quote
Old 2010-08-31, 18:48   #1258
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

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))
was the best I could do I think
science_man_88 is offline   Reply With Quote
Old 2010-08-31, 18:50   #1259
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

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.
CRGreathouse is offline   Reply With Quote
Old 2010-08-31, 20:04   #1260
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

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

I have 10 values left.
3.14159 is offline   Reply With Quote
Old 2010-08-31, 20:16   #1261
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
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.
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 is offline   Reply With Quote
Old 2010-08-31, 20:21   #1262
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

I gave up on matrices.

Code:
multiplication(i,j=i)= for(i=1,i,for(j=1,j,print1(i*j"\t"));print(""))
science_man_88 is offline   Reply With Quote
Old 2010-08-31, 20:34   #1263
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
1) I couldn't get [] to work for matrices
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:
Originally Posted by science_man_88 View Post
2) I wanted the whole table but I couldn't get it all to print
Just return the matrix.

Code:
foo(i,j)=matrix(i,j,x,y,x*y)
CRGreathouse is offline   Reply With Quote
Old 2010-08-31, 20:35   #1264
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I gave up on matrices.

Code:
multiplication(i,j=i)= for(i=1,i,for(j=1,j,print1(i*j"\t"));print(""))
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.
CRGreathouse is offline   Reply With Quote
Old 2010-08-31, 20:39   #1265
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
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)
I tried your idea:

Code:
***   too many arguments: ...plication(i,j=i)=x=Mat(i,j,x,y,x*y);for(i=1,i
                                                      ^--------------------

Last fiddled with by science_man_88 on 2010-08-31 at 20:41
science_man_88 is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I sometimes see all the <> formatting commands when I quote or edit? cheesehead Forum Feedback 3 2013-05-25 12:56
Passing commands to PARI on Windows James Heinrich Software 2 2012-05-13 19:19
Ubiquity commands Mini-Geek Aliquot Sequences 1 2009-09-22 19:33
64-bit Pari? CRGreathouse Software 2 2009-03-13 04:22
Are these commands correct? jasong Linux 2 2007-10-18 23:40

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


Fri Aug 6 23:13:50 UTC 2021 up 14 days, 17:42, 1 user, load averages: 4.55, 4.31, 4.10

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

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.