Sequence 1, 2, 4, 12

7 ビュー (過去 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 Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by