//Faire un polynome et le tracer à l'aide de horner

p = poly([3 0 2 1], 'x', 'c');
x = -100:100;
plot(horner(p,x),x);

M = [   20.202020202020201        42021.447305418216     
40.404040404040401        333020.81760261528     
60.606060606060609        1120345.5474023989     
80.808080808080803        2651342.0732155754     
101.01010101010101        5173356.8315529544     
121.21212121212122        8933736.2589253429     
141.41414141414143        14179826.791843548     
161.61616161616161        21158974.866818368     
181.81818181818181        30118526.920360629     
202.02020202020202        41305829.388981134     
222.22222222222223        54968228.709190674     
242.42424242424244        71353071.317500070     
262.62626262626264        90707703.650420144     
282.82828282828285        113279472.14446169     
303.03030303030300        139315723.23613542     
323.23232323232321        169063803.36195230     
343.43434343434342        202771058.95842311     
363.63636363636363        240684836.46205854     
383.83838383838383        283052482.30936956     
404.04040404040404        330121342.93686688     
424.24242424242425        382138764.78106129     
444.44444444444446        439352094.27846366     
464.64646464646466        502008677.86558479     
484.84848484848487        570355861.97893548     
505.05050505050502        644640993.05502629     
525.25252525252529        725111417.53036857     
545.45454545454550        812014481.84147286     
565.65656565656570        905597532.42484963     
585.85858585858591        1006107915.7170101     
606.06060606060601        1113792978.1544645     
626.26262626262621        1228900066.1737244     
646.46464646464642        1351676526.2113006     
666.66666666666663        1482369704.7037032     
686.86868686868684        1621226948.0874438     
707.07070707070704        1768495602.7990329     
727.27272727272725        1924423015.2749808     
747.47474747474746        2089256531.9517994     
767.67676767676767        2263243499.2659984     
787.87878787878788        2446631263.6540890     
808.08080808080808        2639667171.5525823     
828.28282828282829        2842598569.3979883     
848.48484848484850        3055672803.6268187     
868.68686868686871        3279137220.6755848     
888.88888888888891        3513239166.9807959     
909.09090909090912        3758225988.9789639     
929.29292929292933        4014345033.1065984     
949.49494949494954        4281843645.8002119     
969.69696969696975        4560969173.4963140     
989.89898989898995        4851968962.6314154     
1010.1010101010100        5155090359.6420269     
1030.3030303030303        5470580710.9646597     
1050.5050505050506        5798687363.0358267     
1070.7070707070707        6139657662.2920341     
1090.9090909090910        6493738955.1697989     
1111.1111111111111        6861178588.1056242     
1131.3131313131314        7242223907.5360289     
1151.5151515151515        7637122259.8975153     
1171.7171717171718        8046120991.6266022     
1191.9191919191919        8469467449.1597939     
1212.1212121212120        8907408978.9336033     
1232.3232323232323        9360192927.3845482     
1252.5252525252524        9828066640.9491272     
1272.7272727272727        10311277466.063862     
1292.9292929292928        10810072749.165255     
1313.1313131313132        11324699836.689823     
1333.3333333333333        11855406075.074072     
1353.5353535353536        12402438810.754520     
1373.7373737373737        12966045390.167665     
1393.9393939393940        13546473159.750036     
1414.1414141414141        14143969465.938126     
1434.3434343434344        14758781655.168461     
1454.5454545454545        15391157073.877535     
1474.7474747474748        16041343068.501877     
1494.9494949494949        16709586985.477980     
1515.1515151515152        17396136171.242371     
1535.3535353535353        18101237972.231548     
1555.5555555555557        18825139734.882034     
1575.7575757575758        19568088805.630325     
1595.9595959595961        20330332530.912949     
1616.1616161616162        21112118257.166401     
1636.3636363636363        21913693330.827194     
1656.5656565656566        22735305098.331852     
1676.7676767676767        23577200906.116871     
1696.9696969696970        24439628100.618774     
1717.1717171717171        25322834028.274059     
1737.3737373737374        26227066035.519260     
1757.5757575757575        27152571468.790855     
1777.7777777777778        28099597674.525375     
1797.9797979797979        29068391999.159328     
1818.1818181818182        30059201789.129230     
1838.3838383838383        31072274390.871574     
1858.5858585858587        32107857150.822891     
1878.7878787878788        33166197415.419682     
1898.9898989898991        34247542531.098457     
1919.1919191919192        35352139844.295723     
1939.3939393939395        36480236701.448013     
1959.5959595959596        37632080448.991806     
1979.7979797979799        38807918433.363640     
2000.0000000000000        40007998001.000000 
];
clf();
plot(M);
[a,b] = reglin(log(M(:,1)'),log(M(:,2)'));
plot(a*x + b,x);

// a donne approximativement le degré du polynome

//Degré 2
clf()
A = [ones(M(:,1)) M(:,1) M(:,1)**2];
Y = M(:,2);
X = A\Y;
p = poly(X','x','c');
plot(M(:,1),M(:,2), 'g');
plot(M(:,1),horner(p,M(:,1)));
sum(abs(Y-horner(p,M(:,1))))
clf()
//Degré 3
A = [ones(M(:,1)) M(:,1) M(:,1)**2 M(:,1)**3];
A = [M(:,1)**3 M(:,1)**2 M(:,1) ones(M(:,1))];
X = A\Y;
p = poly(X','x','c');
plot(M(:,1),M(:,2), 'g');
plot(M(:,1),horner(p,M(:,1)));
sum(abs(Y-horner(p,M(:,1))))
clf()
//Degré 4
A = [ones(M(:,1)) M(:,1) M(:,1)**2 M(:,1)**3 M(:,1)**4];
X = A\Y;
p = poly(X','x','c');
plot(M(:,1),M(:,2), 'g');
plot(M(:,1),horner(p,M(:,1)));
sum(abs(Y-horner(p,M(:,1))))
