Harj. 9 LV

5.4.02 HA

1.

> restart:

Warning, the name changecoords has been redefined

> with(LinearAlgebra):alias(Tr=Transpose,Van=VandermondeMatrix):

> with(plots):

> xd:=[$1..28];

xd := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1...

> yd:=[8,7,6,5,5,4,4,3,3,2$9,3,3,3,4,4,5,6,7,7,7];

yd := [8, 7, 6, 5, 5, 4, 4, 3, 3, 2, 2, 2, 2, 2, 2,...

> n:=nops(yd);

n := 28

>

> plot([seq([xd[i],yd[i]],i=1..n)],style=point,symbol=circle,symbolsize=15);

[Maple Plot]

> datakuva:=%:

> C:=Van(xd,n,3);

C := _rtable[135725884]

> C[1..4,1..3];

_rtable[135810848]

> M:=Tr(C).C;

M := _rtable[135943268]

> B:=evalf(Tr(C).Vector(yd));

B := _rtable[135697928]

> a:=LinearSolve(M,B);

a := _rtable[134635404]

> p2:=a[1]+a[2]*x+a[3]*x^2;

p2 := 8.62210012210012167-.937939455180834214*x+.32...

> display(plot(p2,x=xd[1]..xd[n],color=blue),datakuva);

[Maple Plot]

> solve(diff(p2,x)=0,x);

14.39082687

> tmin:=30+14.39;

tmin := 44.39

> minhetki:=evalf(15*h+44*min+39/100*60*s);

minhetki := 15.*h+44.*min+23.40000000*s

Sekunttien tarkkuuteen tuossa ei voida päästä, joten

> vastaus:=15.44;

vastaus := 15.44

2.

> restart:

Warning, the name changecoords has been redefined

> with(LinearAlgebra):alias(Tr=Transpose,Van=VandermondeMatrix):

> with(plots):

Nyt jo tuo aletaan osata. Määritellään samantien funktioksi:

> PNS:=(C,ydata)->convert(LinearSolve(Transpose(C).C,Transpose(C).Vector(yd)),list);

PNS := proc (C, ydata) options operator, arrow; con...
PNS := proc (C, ydata) options operator, arrow; con...

> # C:=Van(xd,nops(xd),deg+1); kertoimet:=PNS(C,yd); poly:=sum(kertoimet[i]*x^(i-1),i=1..deg+1);

> xd:=evalf([1940, 1950, 1960, 1970, 1980, 1990]); # On syytä siirtyä liukulukuihin.

xd := [1940., 1950., 1960., 1970., 1980., 1990.]

>
yd:=[132.165, 151.326, 179.323, 203.302, 226.542, 249.633];
Pisteet:=[seq([xd[i],yd[i]],i=1..nops(xd))];

yd := [132.165, 151.326, 179.323, 203.302, 226.542,...

Pisteet := [[1940., 132.165], [1950., 151.326], [19...

> C1:=Van(xd,nops(xd),2); kertoimet:=PNS(C1,yd);

C1 := _rtable[135212824]

kertoimet := [-4508.59003809589922, 2.3913342857146...

> poly1:=sum(kertoimet[i]*x^(i-1),i=1..2);

poly1 := -4508.59003809589922+2.39133428571462224*x...

> display(plot(Pisteet,style=point,symbol=circle,symbolsize=17),plot(poly1,x=1930..2000,color=green));

[Maple Plot]

> C2:=Van(xd,nops(xd),3); kertoimet:=PNS(C2,yd);

C2 := _rtable[135855252]

kertoimet := [-4079.75047766127409, 1.9548233887372...

> poly2:=sum(kertoimet[i]*x^(i-1),i=1..3);

poly2 := -4079.75047766127409+1.95482338873728190*x...

> display(plot(Pisteet,style=point,symbol=circle,symbolsize=17),plot(poly2,x=1930..2000,color=green));

[Maple Plot]

> C3:=Van(evalf(xd),nops(xd),4); kertoimet:=PNS(C3,yd);

C3 := _rtable[135182476]

kertoimet := [2458463.82484111609, -3757.9815708858...

> poly3:=sum(kertoimet[i]*x^(i-1),i=1..4);

poly3 := 2458463.82484111609-3757.98157088580137*x+...

> display(plot(Pisteet,style=point,symbol=circle,symbolsize=17),plot(poly3,x=1930..2000,color=green));

[Maple Plot]

3.

> restart:

Warning, the name changecoords has been redefined

> with(LinearAlgebra):alias(Tr=Transpose,Van=VandermondeMatrix):

> with(plots):

> #read("c:\\opetus\\maple\\v202.mpl"):
read("/home/apiola/opetus/peruskurssi/v2-3/maple/v202.mpl");

> op(SD2):

> f:=(x,y)->exp(x)*(4*x^2+2*y^2+4*x*y+2*y+1);

f := proc (x, y) options operator, arrow; exp(x)*(4...

> fv:=xx->f(xx[1],xx[2]);

fv := proc (xx) options operator, arrow; f(xx[1],xx...

>

> reitti:=SD2(f,([0,0]),4);

reitti := [[0, 0], [-.1280701802, -.2561403605], [....
reitti := [[0, 0], [-.1280701802, -.2561403605], [....

> map(fv,reitti);

[1, .7176976791, .4730896205, .3272026144, .2063869...

> Newtopt2(f,(reitti[5]),5);

[[.3117682892, -.6114634415], [.618561355500000020,...
[[.3117682892, -.6114634415], [.618561355500000020,...
[[.3117682892, -.6114634415], [.618561355500000020,...

Kuvien piirtämiset ym. SD.mws:ssä ja muut ohjeet harj9ohje.mws:ssä.

Huom! Versiossa 7 Maple valittaa float[8]-vaikerruksen ja sortuu. Siinä pitäisi tutkia tietotyyppejä (float[16]).

>