Sequence 1, 2, 4, 12

6 Ansichten (letzte 30 Tage)
Eduardo de la Rosa
Eduardo de la Rosa am 17 Sep. 2021
Beantwortet: Hernia Baby am 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.

Antworten (2)

Matt J
Matt J am 17 Sep. 2021
Bearbeitet: Matt J am 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 am 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

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by