Message Boards Message Boards

0
|
2418 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Creating an IMPROPER multiplication table(learning how to use And command)?

Posted 8 years ago

I have a multiplication table I want to create, but I want it be to be wrong.. Meaning that for the products of numbers that are EVEN, I actually want the answer to be that product + 1. So 44 = 16+1 = 17, 22 = 4+1 =5 and so on for all the even numbers. The odd numbers can stay the same. I'm trying to learn how to use the "And" command in this process. I have some temporary code:

TableForm[Table[a*b, {a, 12}, {b, 12}], TableHeadings -> Automatic]

This code produces a proper multiplication table, but I am having trouble determining where to insert And(&&) so that I can manipulate the products of those even numbers.

Any suggestions? I think the command OddQ might help also

POSTED BY: Brandon Davis
3 Replies
Posted 8 years ago

Oh! I like that Marco.

I find it so cool and useful to be able to produce the same outputs using different types of inputs/commands.

I appreciate your method

Brandon

POSTED BY: Brandon Davis

Glad to help. Here's another one - this time without an explicit if-condition:

TableForm[Table[a*b + Mod[a *b + 1, 2], {a, 12}, {b, 12}], TableHeadings -> Automatic]

M.

POSTED BY: Marco Thiel

What about

TableForm[Table[If[OddQ[a*b], a*b, a*b + 1], {a, 12}, {b, 12}], TableHeadings -> Automatic]

or

TableForm[Table[a*b, {a, 12}, {b, 12}] /. x_ /; EvenQ[x] -> x + 1 , TableHeadings -> Automatic]

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract