Problem 8057. (Linear) Recurrence Equations - Generalised Fibonacci-like sequences
This problem is inspired by problems 2187, 3092 and other problems based on Fibonacci sequence.
I haven't seen here many problems based on other recursive sequences such as Lucas numbers, Pell numbers, Padovan sequence or Tribonacci numbers so this is a problem about them all.
Your function input will be N, Init and Rules. Init and Rules represent initial values of sequence and a kernel which denotes recurrence relation:
Init : [ A1 A2 ... Ak] Rules : [ Ck ... C2 C1]
function: f(n) = (Ck) * f(n-k) + ... + (C2) * f(n-2) + (C1) * f(n-1) and f(1) = A1, f(2) = A2, ..., f(k) = Ak,
Init and Rules have the same length, N may be a single number or a vector. Your function should return values of f(N). Example:
% Fibonacci sequence: f(1)=f(2)=1, f(n)=f(n-2)+f(n-1) >> Init = [1 1]; >> Rules = [1 1]; >> N = 1:10; >> fibonacci = recurrence_seq(N,Init,Rules), fibonacci = 1 1 2 3 5 8 13 21 34 55
Other info:
- Different approaches may lead to solutions which won't be able to compute f(n) for n being equal 0 or negative integer. If your solution doesn't return correct answer for those numbers it will still pass if it returns NaNs for n<1.
- Please, try to avoid unnecessary things like strings, ans, etc.
Solution Stats
Problem Comments
Solution Comments
Show commentsGroup

Computational Geometry IV
- 20 Problems
- 12 Finishers
- Minimal cost
- Placing Beads Neatly in a Box
- Convex Hull Capture
- Find the sines of an isosceles triangle when given its area and height
- solid of revolution
- Height of a right-angled triangle
- solid of revolution
- Fun with a compass
- Height of a right-angled triangle
- Minimal cost
- Find the sides of an isosceles triangle when given its area and height from its base to apex
- Find the sines of an isosceles triangle when given its area and height
- Radiation Heat Transfer — View Factors (4)
- Radiation Heat Transfer — View Factors (5)
- The cake is a lie...
- Pancakes for everyone!
- Conic equation
- Why the heck are they blinking!?!?
- Find the Area of a Polygon
- Is It a Snake?
- Placing Beads Neatly in a Box
- Fun with a compass
- Angle bisectors
- Regular polygon bounded by and bounding a circle
- solid of revolution
- Height of a right-angled triangle
- Find the sides of an isosceles triangle when given its area and height from its base to apex
- Find the sines of an isosceles triangle when given its area and height
- Euclidean distance from a point to a polynomial
- Convex Hull Capture
- Under the sea: Snell's law & total internal reflection
Problem Recent Solvers353
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!