Sequence 1, 2, 4, 12

조회 수: 10 (최근 30일)
Eduardo de la Rosa
Eduardo de la Rosa 2021년 9월 17일
답변: Hernia Baby 2021년 9월 18일
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.

답변 (2개)

Matt J
Matt J 2021년 9월 17일
편집: Matt J 2021년 9월 17일
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 2021년 9월 18일
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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by