rosenbrock.plt 2.84 KB
Newer Older
Mathieu Hemery's avatar
Mathieu Hemery committed
1
2
:- use_module(rosenbrock).

3
near(X, Y, Epsilon) :-
4
5
  (Epsilon >= abs(X-Y),!);
  (Error is abs(X-Y),write(Error),fail).
6

7
8
check_integration_1([], _Epsilon) :- !.
check_integration_1([Head|Tail], Epsilon) :-
9
  Head = row(T,A,B),
10
11
12
13
14
15
16
17
18
19
  Sum is A+B, near(1.0, Sum, Epsilon),
  Value is exp(-T), near(B, Value, Epsilon),
  check_integration_1(Tail, Epsilon).

check_integration_2([], _Epsilon) :- !.
check_integration_2([Head|Tail], Epsilon) :-
  Head = row(T,Cos,Sin),
  ValueC is cos(T), near(ValueC, Cos, Epsilon),
  ValueS is sin(T), near(ValueS, Sin, Epsilon),
  check_integration_2(Tail, Epsilon).
20

21
22
23
24
25
26
27
check_integration_ball([], _Epsilon) :- !.
check_integration_ball([Head|Tail], Epsilon) :-
  Head = row(_T,_TT,X,_Y),
  X >= -Epsilon,
  check_integration_ball(Tail, Epsilon).


Mathieu Hemery's avatar
Mathieu Hemery committed
28
29
:- begin_tests(rosenbrock).

30
test(eva_coeff_1) :-
31
  nb_setval(hdid,0.01),
32
33
34
35
36
37
38
39
40
  rosenbrock:eval_coeff(1*[0],[1.5,2.5,3.5],[-1,2], 1, R1), R1 =:= 1.5,
  rosenbrock:eval_coeff(2*[0] + p(1),[1.5,2.5,3.5],[-1,2], 1, R2), R2 =:= 5.0,
  rosenbrock:eval_coeff(t,[1.5,2.5,3.5],[-1,2], 1.23, R3), R3 =:= 1.23,
  rosenbrock:eval_coeff(2*[0] - p(0),[1.5,2.5,3.5],[-1,2], 1, R4), R4 =:=4.0,
  rosenbrock:eval_coeff(-p(1),[1.5,2.5,3.5],[-1,2], 1, R5), R5 =:= -2,
  rosenbrock:eval_coeff(25/[1],[1.5,2.5,3.5],[-1,2], 1, R6), R6 =:= 10,
  rosenbrock:eval_coeff([1]^p(1),[1.5,2.5,3.5],[-1,2], 1, R7), R7 =:= 6.25.

test(eva_coeff_2) :-
41
  nb_setval(hdid,0.01),
42
43
44
  rosenbrock:eval_coeff(floor(1*[0]),[1.5,2.5,3.5],[-1,2], 1, R1), R1 =:= 1,
  rosenbrock:eval_coeff(min([0], p(1)),[1.5,2.5,3.5],[-1,2], 1, R2), R2 =:= 1.5,
  rosenbrock:eval_coeff(infinity,[1.5,2.5,3.5],[-1,2], 1, R3), R3 =:= inf,
45
  rosenbrock:eval_coeff(random,[1.5,2.5,3.5],[-1,2], 1, _R4).
46

47
test(simple_integration, [setup(command(clear_model)), cleanup(command(clear_model))]) :-
HEMERY Mathieu's avatar
HEMERY Mathieu committed
48
49
  command(a => b),
  command(present(a,1.0)),
50
51
  command(numerical_simulation(method:rsbk)),
  get_table_data(D),
52
  check_integration_1(D, 1e-5).
53

54
test(cosinus_integration, [setup(command(clear_model)), cleanup(command(clear_model))]) :-
55
56
57
58
59
  command(1.0*a for "_" => b),
  command(-1.0*b for "_" => a),
  command(present(a,1.0)),
  command(numerical_simulation(method:rsbk)),
  get_table_data(D),
60
  check_integration_2(D, 1e-5).
HEMERY Mathieu's avatar
HEMERY Mathieu committed
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
test(test_ball, [setup(command(clear_model)), cleanup(command(clear_model))]) :-
  command(load("library/examples/RobustMonitoring/ball.bc")),
  command(option(maximum_step_size:1e-2)),
  command(numerical_simulation(method:rsbk)),
  get_table_data(D),
  check_integration_ball(D, 1e-3).

test(test_time_event, [setup(command(clear_model)), cleanup(command(clear_model))]) :-
  command(k*a for a => b),
  command(present(a,1.0)),
  command(parameter(k=1)),
  command(add_event('Time'>2, k=0)),
  command(add_event('Time'>=4, k=1)),
  command(numerical_simulation(method:rsbk, time:5)),
  get_table_data(D),
  last(D, row(T,_B,A)),
  near(A, exp(2-T), 1e-5).

Mathieu Hemery's avatar
Mathieu Hemery committed
80
:- end_tests(rosenbrock).