Sequence 1, 2, 4, 12

7 views (last 30 days)
Eduardo de la Rosa
Eduardo de la Rosa on 17 Sep 2021
Answered: Hernia Baby on 18 Sep 2021
Hi everyone!
I need to know the rule for generating the following sequence: 1, 2, 4, 12 (that's all, no more values in the sequence). Does anyone have an idea for the rule to go forward (1-->2-->4-->12) and backward (12-->4-->2-->1)?
Any help is really apreciated! Thanks in advance.

Answers (2)

Matt J
Matt J on 17 Sep 2021
Edited: Matt J on 17 Sep 2021
One possibility:
p=[0.833333333333333 -4.499999999999996 8.666666666666661 -3.999999999999996];
polyval(p,1:4)
ans = 1×4
1.0000 2.0000 4.0000 12.0000
polyval(p,4:-1:1)
ans = 1×4
12.0000 4.0000 2.0000 1.0000

Hernia Baby
Hernia Baby on 18 Sep 2021
You can use polyfit and polyval.
Here is one of examples.
n = 6;
x = 1:4;
y = [1,2,4,12];
p = polyfit(x,y,n)
Warning: Polynomial is not unique; degree >= number of data points.
p = 1×7
0.0098 -0.0438 0 0.2487 0 0 0.7853
x1 = linspace(0,4,100);
y1 = polyval(p,x1);
figure
plot(x,y,'o')
hold on
plot(x1,y1)
hold off

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!