Skip to content

Instantly share code, notes, and snippets.

View faze-geek's full-sized avatar
:octocat:

Anurag Bhat faze-geek

:octocat:
View GitHub Profile
@faze-geek
faze-geek / matmul.cpp
Last active July 29, 2024 05:07
Custom implementation of `np.matmul` using xtensor.
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include <xtensor/xarray.hpp>
#include <xtensor/xio.hpp>
#include <xtensor/xmath.hpp>
#include <xtensor/xsort.hpp>
#include <xtensor/xview.hpp>
@faze-geek
faze-geek / numpy.cpp
Last active June 12, 2024 15:14
Initial implementation of `ndarray_int` and it's python bindings.
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <numpy.hpp>
namespace py = pybind11;
// Function to parse attributes
int parseAttr(const py::object &obj) {
if (py::isinstance<py::none>(obj)) {
return INT_MAX;
def nichols_numerical_data(system, initial_omega=0.01, final_omega=100, **kwargs):
"""
Returns the numerical data of Nichols plot of the system.
It is internally used by ``nichols_plot`` to get the data
for plotting Nichols plot. Users can use this data to further
analyse the dynamics of the system or plot using a different
backend/plotting-module.
Parameters
==========
def _get_breakaway_points(system):
"""Private method to calculate the breakaway points of a transfer function."""
k_expr = -system.den/system.num
k = diff(k_expr, system.var)
points = solve(k, system.var)
points = [point.evalf() for point in points if point.is_real]
breakaway_points = []
for point in points:
if k_expr.subs(system.var, point) > 0:
@classmethod
def from_coeff_lists(cls, coeff_list, var):
r"""
Creates a new ``TransferFunction`` efficiently from a list of coefficients.
Parameters
==========
coeff_list : List
List comprising of numerator and denominator coefficient lists.
=============================================
Solved Textbook Problems using Control Module
=============================================
Given below, are some comprehensive textbook examples to demonstrate the possible use cases
of the Control Module.
Example 1
---------
@faze-geek
faze-geek / Extensions of bode_plot
Last active May 28, 2023 10:16
The gist has code for Nichols and Margin plots which can be derived from preexisting bode plot.
- bode_phase_plot, bode_plot)
+ bode_phase_plot, bode_plot, margin_plot, nichols_numerical_data, nichols_plot)
__all__ = ['TransferFunction', 'Series', 'MIMOSeries', 'Parallel',
'MIMOParallel', 'Feedback', 'MIMOFeedback', 'TransferFunctionMatrix','gbt',
@@ -12,4 +12,5 @@
'impulse_response_numerical_data', 'impulse_response_plot',
'ramp_response_numerical_data', 'ramp_response_plot',
'bode_magnitude_numerical_data', 'bode_phase_numerical_data',
- 'bode_magnitude_plot', 'bode_phase_plot', 'bode_plot']
@faze-geek
faze-geek / Sympy - Add condition
Last active May 28, 2023 10:14
For linear time invariant models, there is a norm that numerator and denominator should be a polynomial.
--- a/sympy/physics/control/lti.py
+++ b/sympy/physics/control/lti.py
@@ -454,6 +454,9 @@ def __new__(cls, num, den, var):
if not isinstance(var, Symbol):
raise TypeError("Variable input must be a Symbol.")
+ if (num.is_polynomial(var) is False or den.is_polynomial(var) is False):
+ raise TypeError("Numerator and Denominator of TransferFunction must be a polynomial")
+
if den == 0: