Skip to content

Instantly share code, notes, and snippets.

@nicoguaro
Last active September 1, 2021 16:29
Show Gist options
  • Save nicoguaro/9dcd8900427e923a077bd0617dfa7bd2 to your computer and use it in GitHub Desktop.
Save nicoguaro/9dcd8900427e923a077bd0617dfa7bd2 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "dd4302e7",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib notebook"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "afd3fd23",
"metadata": {},
"outputs": [],
"source": [
"from ldds.base import compute_lagrangian_descriptor\n",
"from ldds.tools import draw_all_lds"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2843727f",
"metadata": {},
"outputs": [],
"source": [
"def pendulum(t, u):\n",
" x, y = u.T\n",
" v = np.column_stack([y, -np.sin(x)])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0c7ec93b",
"metadata": {},
"outputs": [],
"source": [
"# Mesh parameters to calculate LDs\n",
"\n",
"# 2D Domain\n",
"x_min,x_max = [-4, 4]\n",
"y_min,y_max = [-4, 4]\n",
"\n",
"# Grid size\n",
"Nx, Ny = [50, 50]\n",
"\n",
"grid_parameters = [(x_min, x_max, Nx), (y_min, y_max, Ny)]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "376e4bf1",
"metadata": {},
"outputs": [],
"source": [
"vector_field = lambda t,u: pendulum(t, u)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e1fb9633",
"metadata": {},
"outputs": [],
"source": [
"# Integration parameters (Calculate LDs at time t = t0 by integrating in the interval [t0-tau,t0+tau])\n",
"t0 = 0\n",
"tau = 1\n",
"\n",
"# LDs definition (we will use the p-value seminorm)\n",
"p_value = 0.5\n",
"\n",
"LD_forward = compute_lagrangian_descriptor(grid_parameters, vector_field, tau, p_value)\n",
"LD_backward = compute_lagrangian_descriptor(grid_parameters, vector_field, -tau, p_value)\n",
"\n",
"figs = draw_all_lds(LD_forward, LD_backward, grid_parameters, tau, p_value)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "84c58748",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment