Skip to content

Instantly share code, notes, and snippets.

@silgon
silgon / 2d_curve_fit.py
Last active April 30, 2024 14:56
Python curve_fit function with 2d data
# curvefit with non linear least squares (curve_fit function)
import numpy as np
from scipy.optimize import curve_fit
def func(x, a, b, c):
return a*np.sin(x[0])+b*np.cos(x[1])+c
limits = [0, 2*np.pi, 0, 2*np.pi] # [x1_min, x1_max, x2_min, x2_max]
side_x = np.linspace(limits[0], limits[1], 100)
side_y = np.linspace(limits[2], limits[3], 100)
@silgon
silgon / write_read_json.jl
Last active April 18, 2024 01:31
How to Read and Write JSON files in julia
import JSON
###################
### Write data ####
###################
# dictionary to write
dict1 = Dict("param1" => 1, "param2" => 2,
"dict" => Dict("d1"=>1.,"d2"=>1.,"d3"=>1.))
# pass data as a json string (how it shall be displayed in a file)
stringdata = JSON.json(dict1)
@silgon
silgon / distance_angle_pose_to_point.cpp
Last active March 21, 2024 02:59
Get distance and angle of the closest obstacle from pose and map
#include <ros/ros.h>
#include <nav_msgs/OccupancyGrid.h>
#include <geometry_msgs/PoseStamped.h>
#include <tf/tf.h>
#include <tf/transform_listener.h>
#include <iterator>
#include <vector>
// some definitions of functions
#define MAP_INDEX(map, i, j) ((i) + (j) * map.size_x)

Installation of IPOPT on LINUX

NOTE: this page is for a from-source install (useful if you want to contribute to CasADi). If you just want to evaluate CasADi quickly, use a binary install.

  • To get started quickly, start off by grabbing as many dependencies as possible from repositories.
  • Ubuntu: sudo apt-get install gcc g++ gfortran git cmake liblapack-dev pkg-config --install-recommends
  • Fedora: sudo yum install gcc gcc-c++ gcc-gfortran git cmake lapack-devel
  • To compile the Python interface, you also need SWIG and a decent Python installation:
  • Ubuntu: sudo apt-get install swig ipython python-dev python-numpy python-scipy python-matplotlib --install-recommends
  • Fedora: sudo yum install swig ipython python-devel numpy scipy python-matplotlib
import matplotlib.pyplot as plt
from qiskit import *
from qiskit.tools.monitor import job_monitor
from qiskit.tools.visualization import plot_bloch_multivector, plot_histogram
from math import pi
qr = QuantumRegister(3, name="q")
crz, crx = ClassicalRegister(1, name="crz"), ClassicalRegister(1, name="crx")
c0 = ClassicalRegister(1, name="c0")
import qutip
import matplotlib.pyplot as plt
import numpy as np
b = qutip.Bloch()
# vec = [0,1,0]
th = np.linspace(0, np.pi, 20)
xz = np.sin(th)
yz = np.zeros(20)
zz = np.cos(th)
@silgon
silgon / exploit_structure.jl
Last active July 6, 2023 22:44
exploit_structure.jsl
using SparseArrays
using LinearAlgebra
using BandedMatrices
using SpecialMatrices
using ToeplitzMatrices
using Random
using BlockArrays
using FFTW
BLAS.set_num_threads(1)
import numpy as np
import cvxpy as cp
α = 0.3
A = np.array([[1., α], [α, 1.5]])
# maximum eigenvalue
t = cp.Variable()
prob = cp.Problem(cp.Minimize(t), [np.eye(2)*t-A>>0])
prob.solve()
# minimum eigenvalue
t = cp.Variable()

Sanity check for convex optimization set

image

@silgon
silgon / bluetooth.md
Created March 14, 2018 09:25
Some info about bluetooth with linux