~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to tests/matopt.tst

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright INRIA
 
2
Leps=8.e-5;
 
3
bs=10.*ones(1,5);bi=-bs;x0=0.12*bs;epsx=1.e-15*x0;xopt=.1*bs;
 
4
[f,x,g]=optim('genros',x0,'in');
 
5
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
6
[f,x,g]=optim('genros',x0,'gc','in');
 
7
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
8
//
 
9
 
 
10
[f,x,g]=optim('genros',x0,'nd','in');
 
11
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
12
 
 
13
[f,x,g]=optim('genros',x0,'qn',1,'in');
 
14
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
15
[f,x,g]=optim('genros',x0,'gc',1,50,'in');
 
16
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
17
//
 
18
[f,x,g]=optim('genros',x0,'nd',1,50,'in');
 
19
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
20
 
 
21
[f,x1,g]  =optim('genros',x0,   'ar',100,6,'in');
 
22
[f,x,g,to]=optim('genros',x0,   'ar',100,3,'in');
 
23
[f,x,g,to]=optim('genros',x ,to,'ar',100,3,'in');
 
24
if norm(x-x1)/norm(x-xopt) > 0.1 then  pause,end
 
25
[f,x1,g]=optim('genros','b',bi,bs,x0,'ar',100,6,'in');
 
26
[f,x,g,to]=optim('genros','b',bi,bs,x0,'ar',100,3,'in');
 
27
[f,x,g]   =optim('genros','b',bi,bs,x,to,'ar',100,3,'in');
 
28
if norm(x-x1)/norm(x-xopt) > 0.1 then  pause,end
 
29
[f,x,g]=optim('genros',x0,'ar','in');
 
30
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
31
[f,x,g]=optim('genros',x0,'ar',100,'in');
 
32
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
33
[f,x,g]=optim('genros',x0,'ar',100,100,'in');
 
34
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
35
[f,x,g]=optim('genros',x0,'ar',100,100,%eps,'in');
 
36
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
37
[f,x,g]=optim('genros',x0,'ar',100,100,%eps,%eps,'in');
 
38
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
39
[f,x,g]=optim('genros',x0,'ar',100,100,10.*%eps,%eps,epsx,'in');
 
40
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
41
[f,x,g]=optim('genros',x0,'gc','ar',100,100,%eps,%eps,epsx,'in');
 
42
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
43
//
 
44
[f,x,g]=optim('genros','b',bi,bs,x0,'in');
 
45
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
46
[f,x,g]=optim('genros','b',bi,bs,x0,'gc','in');
 
47
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
48
[f,x]=optim('genros','b',bi,bs,x0,'ar',100,100,1.d-8,'in');
 
49
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
50
[f,x,g]=optim('genros',..
 
51
   'b',bi,bs,x0,'gc','ar',100,100,%eps,%eps,epsx,'in');
 
52
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
53
[f,x,g,to,td]=optim('genros',x0,'in','sd');
 
54
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
55
[f,x,g,ti]=optim('genros',x0,'gc','in','si');
 
56
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
57
[f,x,g,to,ti,td]=optim('genros',x0,to,'in','si','sd');
 
58
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
59
[f,x,g,td]=optim('genros',..
 
60
   'b',bi,bs,x0,'gc','ar',100,100,%eps,%eps,epsx,'in','sd');
 
61
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
62
[f,x,g,ti]=optim('genros',x0,'gc','ar',100,100,%eps,'in','si');
 
63
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
64
[f,x,g,ti,td]=optim('genros',..
 
65
    x0,'gc','ar',100,100,%eps,'in','si','sd');
 
66
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
67
[f,x,g,ti,td]=optim('genros',..
 
68
    x0,'gc','ar',100,100,%eps,'in','ti',ti,'td',td,'si','sd');
 
69
if abs(f-1+norm(x-xopt) ) > Leps then pause,end
 
70
//
 
71
//********************************************************************
 
72
//
 
73
bs=[5 5];bi=-bs;x0=1.05*[1 1];xopt=[1 1];
 
74
deff('[f,g,ind]=rose(x,ind)', 'a=x(2)-x(1)^2 , b=1-x(2) ,...
 
75
f=50.*a^2 + b^2 , g(1)=-400.*x(1)*a , g(2)=200.*a -2.*b ');
 
76
comp(rose);
 
77
//[f,x,g,tr]=optim(rose,x0,'qn','ar',50);if abs(f+norm(x-xopt)) > Leps then pause,end
 
78
//[f,x,g]=optim(rose,x0,tr,'ar',50);if abs(f+norm(x-xopt)) > Leps then pause,end
 
79
[f,x,g]=optim(rose,x0,'gc','ar',50);if abs(f+norm(x-xopt)) > Leps then pause,end
 
80
//
 
81
[f,x,g]=optim(rose,x0,'nd','ar',50);
 
82
if abs(f+norm(x-xopt)) > Leps then pause,end
 
83
 
 
84
[f,x,g]=optim(rose,'b',bi,bs,x0,'qn','ar',25);
 
85
if abs(f+norm(x-xopt)) > Leps then pause,end
 
86
[f,x,g]=optim(rose,'b',bi,bs,x0,'gc','ar',50);
 
87
if abs(f+norm(x-xopt)) > Leps then pause,end
 
88
[f,x,g,td]=optim(rose,x0,'gc','ar',50,'sd');
 
89
if abs(f+norm(x-xopt)) > Leps then pause,end
 
90
[f,x,g,ti]=optim(rose,x0,'gc','ar',50,'si');
 
91
if abs(f+norm(x-xopt)) > Leps then pause,end
 
92
[f,x,g,ti,td]=optim(rose,x0,'gc','ar',50,'si','sd');
 
93
if abs(f+norm(x-xopt)) > Leps then pause,end
 
94
//
 
95
// penalization (see doc)
 
96
//
 
97
// min (x1^2 +x2^2)/2 ; x1>=0, x1 + x2 =1 (solution [0.5 0.5] )
 
98
deff('[f,g,ind]=sip2(x,ind)',..
 
99
' f= [ x(1)+x(2)-1, -x(1), (x(1)^2+x(2)^2)/2],..
 
100
  g= [ 1, -1, x(1); 1,  0, x(2)] ');
 
101
cpen=50; ne=1; nc=2;bi=[0 0]; bs=[2 2];
 
102
deff('[fpen,gpen,ind]=sipn(x,ind,sip1,ne,nc,cpen)',...
 
103
['[f,g,indic]=sip1(x,ind)';
 
104
'if indic < 0 then ind=indic, return, end';
 
105
'if nc >ne then for i=ne+1:nc, f(i)=maxi([0 f(i)]), end,end';
 
106
'fpen=f(nc+1) + cpen*norm(f(1:nc))^2/2';
 
107
'if ind==2 then return,end';
 
108
'gpen=g(:,nc+1)';
 
109
'if ne > 0 then';
 
110
'   for i=1:ne, gpen=gpen + cpen*f(i)*g(:,i),end,end';
 
111
'if nc > ne then';
 
112
' for i=ne+1:nc, if f(i) > 0 then gpen=gpen + cpen*f(i)*g(:,i),end,end;end;'])
 
113
comp(sipn);
 
114
[f,x,g]=optim(list(sipn,sip2,ne,nc,cpen),...
 
115
              'b',bi,bs,[1 1],'ar',20,20,1.e-15);
 
116
if norm(x-[0.5 0.5]) + norm(g) > 0.1 then pause,end
 
117
//********************************************************************
 
118
deff('[f,g,ind]=ndsim(x,ind)', 'y=A*x-b;f=norm(y,2)^2;g=2*A''*y')
 
119
A=rand(2,2);b=eye(A);
 
120
[f,X,g]=optim(ndsim,eye(2,2));
 
121
if norm(X-inv(A))>Leps then pause,end
 
122
 
 
123
deff('[f,g,ind]=ndsim(x,ind)', 'y=A*x-b;f=sum(abs(y));g=A''*sign(y)')
 
124
A=rand(2,2);b=[1;0];Ai=inv(A);
 
125
[f,x,g]=optim(ndsim,[1;0],'nd');
 
126
if norm(x-Ai(:,1))>Leps then pause,end
 
127
 
 
128
deff('[f,g,ind]=ndsim(x,ind)', [
 
129
'y=A*x-b;f=max(abs(y)),sel=abs(y)==f'
 
130
'g=A(sel,:)''*sign(y(sel))']);
 
131
//A=rand(2,2);b=[1;0];Ai=inv(A);
 
132
//[f,x,g]=optim(ndsim,[1;0],'nd');
 
133
//if norm(x-Ai(:,1))>Leps then pause,end
 
134