File: cos.tst

package info (click to toggle)
scilab 5.2.2-9
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 334,832 kB
  • ctags: 52,586
  • sloc: xml: 526,945; ansic: 223,590; fortran: 163,080; java: 56,934; cpp: 33,840; tcl: 27,936; sh: 20,397; makefile: 9,908; ml: 9,451; perl: 1,323; cs: 614; lisp: 30
file content (90 lines) | stat: -rw-r--r-- 2,754 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - Pierre MARECHAL <pierre.marechal@inria.fr>
//
//  This file is distributed under the same license as the Scilab package.
// =============================================================================

// <-- JVM NOT MANDATORY -->

// unit tests for cos() function (element wise cosine)
// =============================================================================


// 1. Interface
// ============

if execstr("cos()"   ,"errcatch")           == 0 then pause, end
if execstr("cos(1,2)","errcatch")           == 0 then pause, end
if execstr("cos(''my string'')","errcatch") == 0 then pause, end

// 2. Singular Values
// ==================

rt2 = sqrt(2);
rt3 = sqrt(3);

x = [0, %pi/6 , %pi/4 , %pi/3 , %pi/2 , 2*%pi/3 , 3*%pi/4   , 5*%pi/6  , %pi ];
v = [1, rt3/2 , rt2/2 , 1/2   , 0     , - 1/2   , - rt2/2   , -rt3/2   , -1  ];

if or(abs(cos(x)-v) > sqrt(%eps)) then pause, end


// 3. Not A Number
// ===============

if ~isnan(cos(%nan)) then pause, end
if ~isnan(cos(-%nan)) then pause, end


// 4. Limit values
// ===============

if ~isnan(real(cos(%inf)))    then pause, end
if imag(cos(%inf)) <> 0       then pause, end

if ~isnan(real(cos(-%inf)))   then pause, end
if imag(cos(-%inf)) <> 0      then pause, end



// 5. Properties
// =============

A = rand(100,100);
B = rand(100,100);

// cos(-x) = cos(x)
if or( cos(-A) - cos(A) > %eps) then pause, end

// cos(%pi/2 - x) = sin(x)
if or( cos(%pi/2 - A) - sin(A) > %eps) then pause, end

// cos(%pi - x) = - cos(x)
if or( cos(%pi - A) + cos(A) > %eps) then pause, end

// cos(%pi + x) = - cos(x)
if or( cos(%pi + A) + cos(A) > %eps) then pause, end

// cos(%pi/2 + x) = - sin(x)
if or( cos(%pi/2 + A) + sin(A) > %eps) then pause, end

// cos^2(a) + sin^2(a) = 1
if or( (cos(A)).^2 + (sin(A)).^2 - 1 > %eps) then pause, end

// cos(a + b) = cos(a) cos(b) - sin(a) sin(b)
if or( cos(A + B) - cos(A).*cos(B) + sin(A).*sin(B) > 2 * %eps) then pause, end

// cos(a -b) = cos(a) cos(b) + sin(a) sin(b)
if or( cos(A - B) - cos(A).*cos(B) - sin(A).*sin(B) > 2 * %eps) then pause, end

// sin(a + b) = sin(a) cos(b) + sin(b) cos(a)
if or( sin(A + B) - sin(A).*cos(B) - sin(B).*cos(A) > 2 * %eps) then pause, end

// sin(a -b) = sin(a) cos(b) - sin(b) cos(a)
if or( sin(A - B) - sin(A).*cos(B) + sin(B).*cos(A) > 2 * %eps) then pause, end

// cos(2a) = cos^2(a) - sin^2(a) = 2 cos^2(a) - 1 = 1 - 2 sin^2(a)
if or( cos(2*A) - (cos(A)).^2 + (sin(A)).^2 > 2 * %eps ) then pause, end
if or( cos(2*A) - 2 * (cos(A)).^2 + 1 > 2 * %eps ) then pause, end
if or( cos(2*A) - 1 + 2 * (sin(A)).^2 > 2 * %eps ) then pause, end