Series of sorts- Return 1 or 2 based on even or odd n

In summary, the conversation is discussing creating a series where the term equals 1 if n is odd and 2 if n is even. Different ways of expressing this are suggested, including using the equations 2-n mod(2), 2-[sin^2(\frac{\pi n}{2})], and ##\frac{3+(-1)^n}{2}##.
  • #1
connordurkin
2
0
I would like to create a series where for each term if n is odd the term =1 and if n is even, the term = 2. I.e.

[itex]a_{n} = 1 if \ n \ is \ odd \ and \ a_{n} = 2 \ if \ n \ is \ even[/itex]
 
Mathematics news on Phys.org
  • #2
Can anyone help me come up with some a_n such that this is true?
 
  • #3
So what you are saying is ...

For input n = 1,2,3,4,5...

a_n = 1,2,1,2,1,2There are a number of ways you can do this (click on Equations for Links )...

[itex]2- n mod(2)[/itex]

[itex]2-[sin^2(\frac{\pi n}{2})][/itex]Just a couple that I thought off in my head...
One is discrete, one is continuous
 
  • #4
There is also ##\frac{3+(-1)^n}{2}##
 
  • #5


This series is known as the "alternating series" or "alternating sequence" and can be represented by the mathematical notation a_{n} = (-1)^{n+1}. This notation indicates that the term will alternate between positive and negative values, with odd terms being positive (1) and even terms being negative (-1). This type of series has been studied extensively in mathematics and has many interesting properties and applications. It is an important concept in calculus, where it is used to test for convergence of infinite series. In scientific research, this type of series can also be used to model real-world phenomena that exhibit alternating patterns or behaviors. Overall, the alternating series is a valuable tool in mathematics and can be applied in a variety of contexts.
 

What is the purpose of the "Series of sorts- Return 1 or 2 based on even or odd n" function?

The purpose of this function is to create a series of 1s and 2s based on whether the input number is even or odd.

How does the function determine if a number is even or odd?

The function uses the modulus operator (%) to determine if the input number is divisible by 2. If the remainder is 0, the number is even, and if the remainder is 1, the number is odd.

What happens if a non-numeric value is passed into the function?

If a non-numeric value is passed into the function, it will return an error or undefined value. It is important to make sure the input is a number before using this function.

Can this function be modified to return a different series of numbers?

Yes, this function can be modified to return a different series of numbers. The code can be edited to return any desired sequence of numbers based on the input number being even or odd.

Is this function useful in practical applications?

It depends on the specific application. This function may be useful for creating a pattern of numbers for visual or mathematical purposes. However, it may not be useful for other types of applications.

Similar threads

  • General Math
Replies
7
Views
1K
Replies
1
Views
768
  • General Math
Replies
4
Views
2K
  • General Math
Replies
8
Views
2K
  • General Math
Replies
1
Views
2K
  • General Math
Replies
28
Views
4K
Replies
12
Views
942
Replies
6
Views
686
Replies
6
Views
824
Replies
20
Views
1K
Back
Top