Skip to content

Commit cdaef1c

Browse files
authored
Update README.md
1 parent 6d5ac8d commit cdaef1c

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,57 @@ y_0=0.01624 y_1=0.08735 y_2=0.15765 y_3=0.19518 y_4=0.25469 y_5=0.29667 y_6=0.31
336336
y_0=0.02256 y_1=0.09240 y_2=0.15593 y_3=0.19116 y_4=0.25076 y_5=0.29644 y_6=0.31550 \lambda_0=0.05487 \lambda_1=0.06919 \lambda_2=-0.12387 \lambda_3=0.04207 \lambda_4=0.04428 \lambda_5=-0.05989 \lambda_6=0.03240 a=0.36223 b=0.55462
337337
y_0=0.02314 y_1=0.09356 y_2=0.15671 y_3=0.19159 y_4=0.25059 y_5=0.29598 y_6=0.31499 \lambda_0=0.05373 \lambda_1=0.06689 \lambda_2=-0.12542 \lambda_3=0.04123 \lambda_4=0.04463 \lambda_5=-0.05896 \lambda_6=0.03342 a=0.36185 b=0.55631
338338
```
339+
340+
```Java
341+
package symjava.examples;
342+
import static symjava.symbolic.Symbol.*;
343+
import symjava.matrix.*;
344+
import symjava.symbolic.*;
345+
/**
346+
* Example for PDE Constrained Parameters Optimization
347+
*
348+
*/
349+
public class Example4 {
350+
public static void main(String[] args) {
351+
Func u = new Func("u", x,y,z);
352+
Func u0 = new Func("u0", x,y,z);
353+
Func q = new Func("q", x,y,z);
354+
Func q0 = new Func("q0", x,y,z);
355+
Func f = new Func("f", x,y,z);
356+
Func lamd = new Func("\\lambda ", x,y,z);
357+
358+
Expr reg_term = (q-q0)*(q-q0)*0.5*0.1;
359+
Func L = new Func("L",(u-u0)*(u-u0)/2 + reg_term + q*Dot.apply(Grad.apply(u), Grad.apply(lamd)) - f*lamd);
360+
System.out.println("Lagrange L(u, \\lambda, q) = \n"+L);
361+
362+
Func phi = new Func("\\phi ", x,y,z);
363+
Func psi = new Func("\\psi ", x,y,z);
364+
Func chi = new Func("\\chi ", x,y,z);
365+
Expr[] xs = new Expr[]{u, lamd, q };
366+
Expr[] dxs = new Expr[]{phi, psi, chi };
367+
SymVector Lx = Grad.apply(L, xs, dxs);
368+
System.out.println("\nGradient Lx = (Lu, Llamd, Lq) =");
369+
System.out.println(Lx);
370+
371+
Func du = new Func("\\delta{u}", x,y,z);
372+
Func dl = new Func("\\delta{\\lambda}", x,y,z);
373+
Func dq = new Func("\\delta{q}", x,y,z);
374+
Expr[] dxs2 = new Expr[] { du, dl, dq };
375+
SymMatrix Lxx = new SymMatrix();
376+
for(Expr Lxi : Lx) {
377+
Lxx.add(Grad.apply(Lxi, xs, dxs2));
378+
}
379+
System.out.println("\nHessian Matrix =");
380+
System.out.println(Lxx);
381+
}
382+
}
383+
```
384+
Output in Latex:
385+
Lagrange=
386+
![](https://github.com/yuemingl/SymJava/blob/master/images/ex4_L.png)
387+
Hessian=
388+
![](https://github.com/yuemingl/SymJava/blob/master/images/ex4_hessian.png)
389+
Grad(L)=
390+
![](https://github.com/yuemingl/SymJava/blob/master/images/ex4_grad.png)
391+
Example6: Finite Element Solver for Laplace Equation
392+
![](https://raw.githubusercontent.com/yuemingl/SymJava/master/images/ex6.png)

0 commit comments

Comments
 (0)