Cでもそれなりに簡単に,数値計算系のプログラムを書く事はできますが
それを,表示するのがめんどくさいです.
csv吐いて,gnuplotに食わすのはつまらないのでMatlab互換のGNU Octaveを使ってみます.
http://ayapin.film.s.dendai.ac.jp/~matuda/PlotUtils/Octave/octave.html
http://www.al.cs.kobe-u.ac.jp/~inamoto/unix-tools/useful/octave/index.html#sq
気に入ったら,丁寧に書くかも
octave:1> x=[0:0.1:2*pi]'; octave:2> sinx=[x,sin(x)]; octave:3> gplot sinx行列は [1,2,3,4,5]みたいにつくる.[1:5]でも良い.
gplot [x,sin(x)]が出来ない辺りがショボイ.
x0 y0 x1 y1 : :を渡せば良いと思われる.
rad = [0:0.1:2*pi]'; x = cos(rad); y = sin(rad); circle = [x,y]; gplot circle
function plot_(args) x=[1:length(args)]'; line=[x,args']; gplot line endfunction
plot_ ([1,2,3])こんな風に使えます.
function ret=spline_(pnts) v0=(pnts(3,[1,2])-pnts(1,[1,2]))/2; v1=(pnts(4,[1,2])-pnts(2,[1,2]))/2; ft=[ 2*pnts(2,[1,2]) - 2*pnts(3,[1,2]) + v0 + v1; -3*pnts(2,[1,2]) + 3*pnts(3,[1,2]) - 2*v0 - v1; v0; pnts(2,[1,2])]; ii=1; for t= [0:0.05:1] ts=[t**3, t**2, t, 1]; tmp=ts*ft; ret(ii,1)=tmp(1); ret(ii,2)=tmp(2); ii++; endfor endfunction function ret=spline(pnts) sz=size(pnts); ret=[]; for ii=[1:sz(1)-3] ret= concat(ret', spline_(pnts([ii:ii+3],[1,2]))')'; endfor endfunction function plot_spline(pnts) pnts=concat(pnts(1,[1,2])', pnts')'; pnts=concat(pnts', pnts(size(pnts)(1), [1,2])')'; sp=spline(pnts); sz=size(sp); xs=sp([1:sz(1)],1); ys=sp([1:sz(1)],2); plot(xs,ys); endfunction
octave:2> spline([1 1;3 1; 3 3; 1 3])とかすると,スプライン補完します.
octave:3> plot_spline([1 1;3 1; 3 3; 1 3])プロットもします.