10/06/26 13:24:31
>>89
% Prolog
標本値を採取(LX,LY) :-
findall(X,(for(10,N,40),X is N / 10),LX),
findall(Y,(member(V,LX),Y is log(V)),LY).
ラグランジェ補間(X,Y) :-
標本値を採取(LX,LY),
ラグランジェ補間(LX,LY,X,0.0,Y).
ラグランジェ補間(_,_,[],[],_,Y,Y) :- !.
ラグランジェ補間([B|R1],[C|R2],X,A,Y) :-
ラグランジェ補間(LX,[B|R1],X,1.0,U),
A2 is A + U * C,
ラグランジェ補間(R1,R2,X,A2,Y).
ラグランジェ補間([],_,_,U,U) :- !.
ラグランジェ補間([C|R1],[B|R2],X,D,U) :-
\+(R1=R2),!,
D2 is D * (X-C) / (B-C),
ラグランジェ補間(R1,[B|R2],X,D2,U).
ラグランジェ補間([C|R1],[B|R2],X,D,U) :-
ラグランジェ補間(R1,[B|R2],X,D,U).