# HG changeset patch # User Mike Miller # Date 1367183291 14400 # Node ID 1a3bfb14b5da2c0932e0cf9465cab7e58ca82fcb # Parent 2f766ceeb03e6591932b904022323c36e2098314 Add and fix tests for ellipj, ellipke, and expint * ellipj.cc: Fix demo, add validation tests. * ellipke.m: Fix assert arguments, add tests. * expint.m: Add tests. diff -r 2f766ceeb03e -r 1a3bfb14b5da libinterp/corefcn/ellipj.cc --- a/libinterp/corefcn/ellipj.cc Wed Apr 24 23:22:50 2013 -0400 +++ b/libinterp/corefcn/ellipj.cc Sun Apr 28 17:08:11 2013 -0400 @@ -406,13 +406,14 @@ %! [sn, cn, dn] = ellipj(U,M); %! %! %% Plotting -%! figure(2) %! c = colormap(hot(64)); %! data = {sn,cn,dn}; %! dname = {"sn","cn","dn"}; %! for i=1:3 %! subplot(1,3,i); -%! image(m,u,32*clip(data{i},[-1,1])+32); # clip function belongs to audio package +%! data{i}(data{i} > 1) = 1; +%! data{i}(data{i} < -1) = -1; +%! image(m,u,32*data{i}+32); %! title(dname{i}); %! end %! colormap(c); @@ -911,4 +912,8 @@ %! assert(sn,S,8*eps); %! assert(cn,C,8*eps); %! assert(dn,D,8*eps); + +%!error ellipj () +%!error ellipj (1) +%!error ellipj (1,2,3,4) */ diff -r 2f766ceeb03e -r 1a3bfb14b5da scripts/specfun/ellipke.m --- a/scripts/specfun/ellipke.m Wed Apr 24 23:22:50 2013 -0400 +++ b/scripts/specfun/ellipke.m Sun Apr 28 17:08:11 2013 -0400 @@ -95,7 +95,7 @@ %! [k,e] = ellipke(m); %! %! # K(1.0) is really infinity - see below -%! K = [ +%! k_exp = [ %! 1.5707963267948966192; %! 1.5747455615173559527; %! 1.6124413487202193982; @@ -103,7 +103,7 @@ %! 2.5780921133481731882; %! 3.6956373629898746778; %! 0.0 ]; -%! E = [ +%! e_exp = [ %! 1.5707963267948966192; %! 1.5668619420216682912; %! 1.5307576368977632025; @@ -112,5 +112,38 @@ %! 1.0159935450252239356; %! 1.0 ]; %! if k(7)==Inf, k(7)=0.0; endif; -%! assert(K,k,8*eps); -%! assert(E,e,8*eps); +%! assert(k,k_exp,k,8*eps); +%! assert(e,e_exp,8*eps); + +%% Test against A&S Table 17.1 +%!test +%! m = [0:5:50]'/100; +%! k_exp = [1.570796326794897; +%! 1.591003453790792; +%! 1.612441348720219; +%! 1.635256732264580; +%! 1.659623598610528; +%! 1.685750354812596; +%! 1.713889448178791; +%! 1.744350597225613; +%! 1.777519371491253; +%! 1.813883936816983; +%! 1.854074677301372 ]; +%! e_exp = [1.570796327; +%! 1.550973352; +%! 1.530757637; +%! 1.510121831; +%! 1.489035058; +%! 1.467462209; +%! 1.445363064; +%! 1.422691133; +%! 1.399392139; +%! 1.375401972; +%! 1.350643881 ]; +%! [k,e] = ellipke (m); +%! assert (k, k_exp, 1e-15); +%! assert (e, e_exp, 1e-8); + +%% Test input validation +%!error ellipke () +%!error ellipke (1,2,3) diff -r 2f766ceeb03e -r 1a3bfb14b5da scripts/specfun/expint.m --- a/scripts/specfun/expint.m Wed Apr 24 23:22:50 2013 -0400 +++ b/scripts/specfun/expint.m Sun Apr 28 17:08:11 2013 -0400 @@ -105,3 +105,67 @@ endif endfor endfunction + +%% Test against A&S Table 5.1 +%!test +%! x = [5:5:50]'/100; +%! gamma = 0.5772156649; +%! y_exp = [0.9876375971; +%! 0.9755453033; +%! 0.9637156702; +%! 0.9521414833; +%! 0.9408157528; +%! 0.9297317075; +%! 0.9188827858; +%! 0.9082626297; +%! 0.8978650778; +%! 0.8876841584 ]; +%! y = (expint (x) + log(x) + gamma) ./ x; +%! assert (y, y_exp, 1e-9); +%!test +%! x = [50:5:95]'/100; +%! y_exp = [0.559773595; +%! 0.503364081; +%! 0.454379503; +%! 0.411516976; +%! 0.373768843; +%! 0.340340813; +%! 0.310596579; +%! 0.284019269; +%! 0.260183939; +%! 0.238737524 ]; +%! y = expint (x); +%! assert (y, y_exp, 1e-9); +%!test +%! x = [100:5:145]'/100; +%! y_exp = [0.219383934; +%! 0.201872813; +%! 0.185990905; +%! 0.171555354; +%! 0.158408437; +%! 0.146413373; +%! 0.135450958; +%! 0.125416844; +%! 0.116219313; +%! 0.107777440 ]; +%! y = expint (x); +%! assert (y, y_exp, 1e-9); +%!test +%! x = [150:5:200]'/100; +%! y_exp = [0.100019582; +%! 0.092882108; +%! 0.086308334; +%! 0.080247627; +%! 0.074654644; +%! 0.069488685; +%! 0.064713129; +%! 0.060294967; +%! 0.056204378; +%! 0.052414380; +%! 0.048900511 ]; +%! y = expint (x); +%! assert (y, y_exp, 1e-9); + +%% Test input validation +%!error expint () +%!error expint (1,2)