Geometric Progression
Geometric Progression Generator
Calculate sequences with interactive demo and VB code examples
What is Geometric Progression?
Geometric progression (GP) is a sequence of numbers where each subsequent term is found by multiplying the previous term by a fixed number. This fixed number is called the common ratio (r).
Formula
nth term = a × r(n-1)
Where a = first term, r = common ratio
Examples
2, 4, 8, 16, 32... (a=2, r=2)
81, 27, 9, 3... (a=81, r=1/3)
Constraints
Common ratio cannot be zero
Can be positive or negative
Applications in Real Life
- Finance: Calculating compound interest growth
- Biology: Modeling population growth under ideal conditions
- Physics: Describing radioactive decay processes
- Computer Science: Analyzing algorithm complexity
Interactive GP Calculator
Enter the values below to generate a geometric progression:
Implementation Code
Below are Visual Basic implementations for generating geometric progressions:
Visual Basic 6 Implementation
Private Sub cmd_compute_Click()
Dim x, n, num As Integer
Dim r As Single
' Get values from text boxes
x = Txt_FirstNum.Text
r = Txt_CR
num = Txt_Terms.Text
' Clear list and add headers
List1.Clear
List1.AddItem "n" & vbTab & "x"
List1.AddItem "___________"
' Generate geometric progression
n = 1
Do
' Calculate next term
x = x * r
' Add to list
List1.AddItem n & vbTab & x
' Increment term counter
n = n + 1
Loop Until n = num + 1
End Sub
Key Features
- Uses
Do...Loop Untilfor iteration - Outputs results to a ListBox using
AddItem - Simple and straightforward VB6 approach
VB.NET Implementation
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim firstTerm As Double
Dim commonRatio As Double
Dim numTerms As Integer
Dim results As New List(Of String)
' Validate inputs
If Not Double.TryParse(txtFirstTerm.Text, firstTerm) Then
MessageBox.Show("Please enter a valid number for first term")
Return
End If
If Not Double.TryParse(txtCommonRatio.Text, commonRatio) Then
MessageBox.Show("Please enter a valid number for common ratio")
Return
End If
If Not Integer.TryParse(txtNumTerms.Text, numTerms) OrElse numTerms < 1 Then
MessageBox.Show("Please enter a positive integer for number of terms")
Return
End If
' Clear previous results
lstResults.Items.Clear()
lstResults.Items.Add("Term".PadRight(10) & "Value")
lstResults.Items.Add("".PadRight(20, "-"))
' Calculate and add terms
Dim currentTerm = firstTerm
For termIndex = 1 To numTerms
lstResults.Items.Add($"{termIndex.ToString().PadRight(10)}{currentTerm}")
currentTerm *= commonRatio
Next
End Sub
Key Improvements in VB.NET
- Strong typing with Double and Integer
- Input validation using TryParse
- Modern For loop instead of Do...Loop
- String interpolation for cleaner output
JavaScript Implementation (This Page)
function calculateGP() {
// Get input values
const firstTerm = parseFloat(document.getElementById('firstTerm').value);
const commonRatio = parseFloat(document.getElementById('commonRatio').value);
const numTerms = parseInt(document.getElementById('numTerms').value);
// Validate inputs
if (isNaN(firstTerm) {
alert('Please enter a valid number for first term');
return;
}
if (isNaN(commonRatio)) {
alert('Please enter a valid number for common ratio');
return;
}
if (isNaN(numTerms) || numTerms < 1 || numTerms > 50) {
alert('Please enter a valid number of terms (1-50)');
return;
}
// Generate results
let currentTerm = firstTerm;
let resultsHTML = '';
let sequence = [];
for (let n = 1; n <= numTerms; n++) {
// Format calculation display
const calcDisplay = n === 1 ?
`${firstTerm} × ${commonRatio}0` :
`${firstTerm} × ${commonRatio}${n-1}`;
resultsHTML += `<tr>
<td>${n}</td>
<td>${currentTerm.toFixed(4)}</td>
<td>${calcDisplay}</td>
</tr>`;
sequence.push(currentTerm.toFixed(4));
currentTerm *= commonRatio;
}
// Display results
document.getElementById('gpResults').innerHTML = resultsHTML;
document.getElementById('sequenceSummary').innerHTML = sequence.join(', ');
document.getElementById('resultContainer').style.display = 'block';
}
Key Features
- Input validation with error messages
- Dynamic HTML generation for results table
- Mathematical notation using superscripts
- Sequence summary display
Mathematical Concepts
Key Formulas
Properties
- The ratio between consecutive terms is constant
- When r > 1, sequence grows exponentially
- When 0 < r < 1, sequence decreases to zero
- When r < 0, sequence alternates between positive and negative values
Example Sequences
| First Term | Ratio | Sequence |
|---|---|---|
| 3 | 2 | 3, 6, 12, 24, 48... |
| 100 | 0.5 | 100, 50, 25, 12.5, 6.25... |
| 4 | -2 | 4, -8, 16, -32, 64... |
| 1 | 10 | 1, 10, 100, 1000, 10000... |