Generating Sequences Part 2

This lesson follows on from ‘Using R to generate sequences - Part 1 and demonstrates how to use R to find the relationship between terms, investigate whether a number lies in a sequence and find a missing term

Download .Rmd here

Download word document here

Download pdf here

KS3: Generating Sequences Part 2

Lesson objectives

Investigating sequences

Packages used in this lesson:

Success criteria

Keywords

Remember

Knit your R markdown document frequently. Knit for the final time when you have completed the lesson. This final output file will be the one your teacher marks.

Write your code in the code chunks.

You can run your R code chunk in the Markdown file by clicking on the little arrow on the right of the chunk.

Worked Example 1

This is how you find the difference between the terms in a sequence.

The sequence is 3, 7, 11, 15.

Knit your document to see the sequence generated by the R code in chunk1.

x <- c(3,7,11,15)
diff(x)
[1] 4 4 4

The R code tells you the difference between each number in the sequence.

Activity 1 Questions

Now use the above example R code in chunk1 to find the difference between the terms in the following sequences

Knit the document after each question to see the answer. Check your answer.

Q1 2,7,12,17,22

Q2 3,9,15,21,27

Q3 1,4,10,19,31

Worked Example 2

Now we will see if a number lies in a sequence.

First we will generate the first 20 terms of the sequence 3,7,11,15 and then we will see if the numbers 55 and 56 lie in the sequence. The computer will generate the sequence and if it finds the number it will report it below the sequence. If it does not find it then it will say numeric (0).

Knit your document to see the result.

x <- seq(from=3, length.out=20, by=4)
x
 [1]  3  7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 67 71 75 79
x[x==55]
[1] 55
x[x==56]
numeric(0)

Use the above example R code in chunk5 to answer the following questions.

Remember to tell R how many terms you want it to generate by editing the length.out number. Remember to tell R what numbers to look for in the sequence by editing the x== numbers.

Knit your document to check the results of your R code.

Activity 2 Questions

Q1 Generate the first 100 terms of the sequence 3,7,11,15 and see if the numbers 117 and 395 lie in the sequence. Do they?

Answer:

Worked Example 3

Now we will find the missing number in a sequence. Our sequence is 4, ?, 16, 22. Term 2 is missing. So we generate the sequence based on what we know which is that the difference between 16 and 22 is 6. The computer will put in the missing term.

seq(from=4, to=22, by=6)
[1]  4 10 16 22

Answer: The missing term is 10.

Use the above example R code to answer the following questions.

Remember to knit to see your results.

Activity 3 Questions

Q1 What is the missing term in the sequence 3,12,?,30.

Answer:

KNIT YOUR DOCUMENT for the final time. This will be the version your teacher will mark

THE END

License and Citation: You can use, modify, and adapt any of the lessons, but please include the following attribution: RGirls Community. (2022, April 10). RGirls Lessons. Zenodo. https://doi.org/10.5281/zenodo.6436861