-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcobylatest.html
More file actions
38 lines (30 loc) · 1.04 KB
/
cobylatest.html
File metadata and controls
38 lines (30 loc) · 1.04 KB
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
<html>
<head>
</head>
<script src='Cobyla.js' type='text/javascript'></script>
<body>
<h1>Test cobyla</h1>
This example shows an easy example of nonlinear optimization with JavaScript. Look at the source code! <br>
Copyright notice in Cobyla.js!
<br>
The point on the unit circle closest to (5,5) is:
<script type="text/javascript">
var n=2; // + of variables
var x=new Array(n);
var m=2; // number of constraints
var rhobeg = 5.0; // Various Cobyla constants, see Cobyla docs in Cobyja.js
var rhoend = 1.0e-6;
var iprint = 3;
var maxfun = 3500;
var fmaxiter = 20;
function test(n,m,x,con) { // objective function
con[0]=x[0]*x[0]+x[1]*x[1]-1 // first inequality constraint
con[1]=-(x[0]*x[0]+x[1]*x[1]-1) // second inequality constraint, together an equality constraint
return (x[0]-5)*(x[0]-5)+(x[1]-5)*(x[1]-5); // objective function
}
x[0]=-7.9; x[1]=3.2;
var r=FindMinimum(test, n, m, x, rhobeg, rhoend, iprint, maxfun, fmaxiter);
document.write("Result="+x);
</script>
</body>
</html>