Comments (4)
Nice, thanks for your fast response! I thought a pull request would be a little overkill for that 🙂 so I just opened an Issue. Thanks again!
from pacopy.
Or another 2D-Example:
Just a side-node: I had to use the ugly numpy.array([out0, out1])
code because autograd
is not able to do automatic differentiation with item-assignments of arrays out[0] = ...
. Has nothing to do with pacopy
. I did use the older autograd
instead of its successor jax
as jax
won't install on Windows.
from autograd import numpy
import autograd
import scipy
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import pacopy
class SimpleProblem2D:
def __init__(self):
self.n = 2
def inner(self, a, b):
"""The inner product of the problem. Can be numpy.dot(a, b), but factoring in
the mesh width stays true to the PDE.
"""
return numpy.dot(a, b)
def norm2_r(self, a):
"""The norm in the range space; used to determine if a solution has been found."""
return numpy.dot(a, a)
def f(self, u, lmbda):
"""The evaluation of the function to be solved"""
out0 = numpy.sin(u[0]) - lmbda
out1 = numpy.cos(u[1])*u[1] - lmbda
return numpy.array([out0, out1])
def df_dlmbda(self, u, lmbda):
"""The function's derivative with respect to the parameter. Used in Euler-Newton
continuation.
"""
out = -numpy.ones_like(u)
return out
def jacobian_solver(self, u, lmbda, rhs):
"""A solver for the Jacobian problem."""
df_du = autograd.jacobian(self.f)
return numpy.linalg.solve(df_du(u, lmbda), rhs)
problem = SimpleProblem2D()
# Initial guess
u0 = numpy.zeros(problem.n)
# Initial parameter value
lmbda0 = 0.0
# Init lists
lmbda_list = []
values_list = []
def callback(k, lmbda, sol):
# Use the callback for plotting, writing data to files etc.
lmbda_list.append(lmbda)
values_list.append(sol)
pacopy.euler_newton(problem, u0, lmbda0, callback, max_steps=50, newton_tol=1.0e-10)
# plot solution
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
data = numpy.hstack((numpy.array(values_list),
numpy.array(lmbda_list).reshape(-1,1))).T
ax.plot(*data,'.-')
ax.set_xlabel('$u_1$')
ax.set_ylabel('$u_2$')
ax.set_zlabel('$\lambda$')
from pacopy.
Thanks for the suggestions! I've added some simple ODE examples to the main readme.
from pacopy.
For sure, I fiddled around with it too and created added some plots to the readme.
from pacopy.
Related Issues (12)
- add fenics example
- support for simple 1d bifurcations HOT 3
- Complex-Ginsburg-Landau HOT 7
- reproduce Gross-Pitaevskii results
- stop when <u, u> = 0
- readme dump HOT 1
- no code in main branch HOT 1
- This version of pacopy is outdated. Please upgrade. HOT 2
- milestones HOT 3
- default maximum parameter stepsize HOT 2
- version bump for pacopy.natural.milestones HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pacopy.