Group Abstract Group Abstract

Message Boards Message Boards

0
|
11.3K Views
|
7 Replies
|
1 Total Like
View groups...
Share
Share this post:

[EIWL] list line plot of the first digits of the first 100 squares ?

Posted 10 years ago

At

http://www.wolfram.com/language/elementary-introduction/06-making-tables.html

exercise 6.10 is "Make a list line plot of the first digits of the first 100 squares."

I found a solution

ListLinePlot[Table[First[Part[First[IntegerDigits[{Range[100]^2}]], n]], {n, 100}]]

but surely there has to be a better way. Can someone provide a nicer way of accomplishing the task. I certainly can't! :(

POSTED BY: Peter MacKinnon
7 Replies

Maybe a bit shorter:

ListLinePlot[IntegerDigits[Range[100]^2][[;; , -1]]]

Edit: I misread "the last" digit...

For the First digit:

ListLinePlot[IntegerDigits[Range[100]^2][[;; , 1]]]
POSTED BY: Christian Neel
Posted 1 year ago

This may also be used : ListLinePlot[Table[First[IntegerDigits[n^2]], {n, 100}]]

POSTED BY: Maryam Nk

Since IntegerDigits has attribute Listable, there's no need to Map IntegerDigits onto Range[100]^2. Thus simply;

 ListLinePlot[First /@ IntegerDigits[Range[100]^2]]
POSTED BY: Murray Eisenberg
Posted 10 years ago

Thank-you both Paul and Christian. I shall investigate, and hopefully learn. :)

POSTED BY: Peter MacKinnon

Hello Peter, the ;; is a short form for "All" but is a very simple way to manipulate array without explicit index. have a look at the Mathematica help about Span it is very clearly explained. BTW in that particular case, Paul's proposal is even cleaner because there are no reference to table indexes at all.( /@ being the prefix form for "Map"..see also Map help)

POSTED BY: Christian Neel
Posted 10 years ago

This may also be what you need

ListLinePlot[First /@ IntegerDigits /@ (Range[100]^2)]

Paul.

POSTED BY: Paul Cleary
Posted 10 years ago

Thank-you Christian. Definitely better. Or at least it will be if I can figure out what the [[;; , -1]] is all about.

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