```julia
using BasisFunctions, FrameFun, Plots, DomainSets
FE = FrameFun;BA = BasisFunctions;
```

# 1D Differential Equation (Poisson)


```julia
B = Fourier(41) → -1..1
Dom = -0.5..0.5
```

## Homogenous Dirichlet Boundary Condition


$$\begin{align}p''(x)&=f(x), &x\in\Omega\\ p(x)&= 0, &x \in \delta\Omega\end{align}$$

Boundary conditions are defined by an operator and a function. The solution F satisfies 
    diff*F = df
on the domain boundary.


```julia
diff = IdentityOperator(B)
BC = DirichletBC(x->0);
```

Differential equations are defined by an operator, a function and a boundary condition. The solution F satisfies 
    Diff*F=f
in the interior of the domain.


```julia
fD = x->x;
Diff = differentiation(B)*differentiation(B)
DE = DiffEquation(B,Dom,Diff,fD, (BC,BC));
```


```julia
FD = solve(DE)
```


```julia
# Exact solution
solD = x->x^3/6 - x/24;
```


```julia
plot(FD,layout=4,title="Solution")
plot!(FD'',subplot=2,title="Second derivative")
plot!(FD,solD,subplot=3,title="Solution error")
plot!(FD'',fD,subplot=4,title="Derivative error")
```

## Homogenous Neumann Boundary Condition


$$\begin{align}p''(x)&=f(x), &x\in\Omega\\ p'(x)&= 0, &x \in \delta\Omega\end{align}$$


```julia
diff = differentiation(B)
NeumannBC(x->0.)
```


```julia
fN = x->x;
Diff = differentiation(B)*differentiation(B)
DE = DiffEquation(B,Dom,Diff,fN, (BC,));
```


```julia
FN = solve(DE)
```


```julia
# Exact solution
solN = x->x^3/6-x/8
```


```julia
plot(FN,layout=4,title="Solution")
plot!(FN'',subplot=2,title="Second derivative")
plot!(FN,solN,subplot=3,title="Solution error")
plot!(FN'',fN,subplot=4,title="Derivative error")
```

# 2D Differential Equation 

2D experiments may take some time

## Dirichlet on Annulus (Laplace)

$$\begin{align}
\Delta p(x,y)&=0 &(x,y)\in\Omega\\
p(x,y) &= df(x,y) &(x,y)\in\delta\Omega
\end{align}$$


```julia
B2 = (Fourier(31) → -1..1)^2
D2 = Disk(0.8)\Rectangle(SA[-0.15,-1.0],SA[0.15,0.0])
```


```julia
diff2 = IdentityOperator(B2)
df2D = (x,y) -> x-y;
BC2 = DirichletBC(df2D,DomainSets.euclideanspace(Val(2)))
```


```julia
f2D = (x,y)->0;
Diff2 = differentiation(B2,(2,0))+differentiation(B2,(0,2))
DE2 = DiffEquation(B2,D2,Diff2,f2D, (BC2,));
```


```julia
F2D = solve(DE2,solverstyle=DirectStyle(),directsolver=:qr) 
```


```julia
heatmap(F2D)
```

# Homogenous Neumann on semi-periodic strip (Poisson)

$$\begin{align}
\Delta p(x,y)&=f(x,y) &(x,y)\in\Omega\\
\frac{\delta p}{\delta y}(x,y) &= 0 &(x,y)\in\delta\Omega
\end{align}$$


```julia
B2 = (Fourier(21) → -1..1)^2
D2 = Rectangle(SA[-1.0,-0.5],SA[1.0,0.5])
```


```julia
diff2 = differentiation(B2,(0,1))
df2N = (x,y)->0;
BC2 = NeumannBC(df2N,DomainSets.euclideanspace(Val(2)))
```


```julia
f2N = (x,y)->cos(2*pi*(x+y));
Diff2 = differentiation(B2,(2,0))+differentiation(B2,(0,2))
DE2 = DiffEquation(B2,D2,Diff2,f2N, (BC2,));
```


```julia
F2N = solve(DE2,solverstyle=AZStyle())
```


```julia
heatmap(F2N)
```

## Helmholtz


```julia
using StaticArrays
B2 = (Fourier(41) → -1..1)^2
D2 = Disk(0.75)\Disk(0.2,SVector(0.3,-0.3))
```


```julia
diff2 = IdentityOperator(B2)
df2H = (x,y)->0;
BC = NeumannBC(df2H,DomainSets.euclideanspace(Val(2)))
```


```julia
f2H = (x,y)->exp(-200*((x+0.3)^2+(y-0.3)^2))
Diff2 = differentiation(B2,(2,0))+differentiation(B2,(0,2))+1000*IdentityOperator(B2)
DE2 = DiffEquation(B2,D2,Diff2,f2H, (BC2,));
```


```julia
F2H = FrameFun.solve(DE2,solverstyle=AZStyle())
```


```julia
heatmap(F2H)
```


```julia

```

58c272b9c7179545a08c24a3e934424f087f214a
ipynb
Jupyter Notebook
examples/DiffEquation.ipynb
JuliaApproximation/FrameFun.jl
aa4247015d1bc8528514f86d8b6d82e4886b1976
MIT
2019-07-09T08:33:22.000Z
2022-03-26T03:04:47.000Z
examples/DiffEquation.ipynb
JuliaApproximation/FrameFun.jl
aa4247015d1bc8528514f86d8b6d82e4886b1976
MIT
2019-10-21T13:41:16.000Z
2022-03-23T19:35:05.000Z
examples/DiffEquation.ipynb
JuliaApproximation/FrameFun.jl
aa4247015d1bc8528514f86d8b6d82e4886b1976
MIT
2020-02-08T11:51:27.000Z
2021-11-22T14:46:56.000Z
Qwen/Qwen-72B
1. YES
2. YES