Sequence 1, 2, 4, 12

8 visualizaciones (últimos 30 días)
Eduardo de la Rosa
Eduardo de la Rosa el 17 de Sept. de 2021
Respondida: Hernia Baby el 18 de Sept. de 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.

Respuestas (2)

Matt J
Matt J el 17 de Sept. de 2021
Editada: Matt J el 17 de Sept. de 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 el 18 de Sept. de 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

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by