comparison examples/maths/QuadraticForm.java @ 1:5df24c91468d

Oh my what a mess.
author samer
date Fri, 05 Apr 2019 16:26:00 +0100
parents
children
comparison
equal deleted inserted replaced
0:bf79fb79ee13 1:5df24c91468d
1 package eg.maths;
2 import samer.core.*;
3 import samer.maths.*;
4 import samer.maths.ops.*;
5
6 public class QuadraticForm extends FunctionOfVector
7 {
8 VVector x, yy;
9 Matrix A;
10 MatrixTimesVector Ax;
11 double [] y;
12
13 public QuadraticForm() { this(Shell.getInt("dimensions",2)); }
14 public QuadraticForm(int n)
15 {
16 x = new VVector("x",n);
17 yy = new VVector("y",n);
18 A = new Matrix("A",n,n);
19 Ax = new MatrixTimesVector(yy.array(),A);
20 y = yy.array();
21
22 Shell.put("functionOfVector",this);
23 Shell.put("vector",x);
24 }
25
26 public double apply(double [] x)
27 {
28 Ax.run(x);
29 return -0.5*Mathx.dot(x,y);
30 }
31
32 public VectorFunctionOfVector derivative()
33 {
34 return new VectorFunctionOfVector() {
35
36 public void apply(double [] x) {
37 Ax.run(x);
38 Mathx.copy(y,x);
39 }
40
41 public void apply(double [] x, double [] v) {
42 Ax.run(x);
43 Mathx.copy(y,v);
44 }
45 };
46 }
47 }