Skip to content

Instantly share code, notes, and snippets.

View AnuragAnalog's full-sized avatar

Peddi Anurag AnuragAnalog

View GitHub Profile
@AnuragAnalog
AnuragAnalog / optimize_using_or.py
Created July 5, 2021 13:02
Getting started with OR tools
# Getting started:
# Python3 installation: python -m pip install --upgrade --user ortools
#
# Optimisation with the OR tool can be done in 5 steps:
# Creating a solver
# Creating a variable (x, y, … etc.)
# Creating linear constraints
# Creating an objective function
# Run the solver
#
@AnuragAnalog
AnuragAnalog / bisection.py
Created July 9, 2021 04:00
Bisection method Implementation in Python
# Bisection method which is also known as bolzano method is based on the repeated application of intermediate value property.
# Let the function f(x) be continous between a and b. For definiteness, let f(a) be (-)ve and f(b) be (+)ve. Then the first approximation to the root is x1 = (a+b)/2.
# If f(x1)=0, then x1 is a root of f(x) = 0, otherwise, the root lies between a
# and x1 or x1 and baccording to f(x1) is (+)ve or (-)ve. Then we bisect the
# interval as before and continue the process until the root is found to the desird accuracy.
#!/usr/bin/python3.6
def f(x):
fx = 3*x**2-15*x+7
@AnuragAnalog
AnuragAnalog / bisection.c
Created July 9, 2021 04:05
Bisection method Implementation in C
/********* Bisection method which is also known as bolzano method is based on the repeated application of intermediate value property.
Let the function f(x) be continous between a and b. For definiteness, let f(a) be (-)ve and f(b) be (+)ve. Then the first approximation to the root is x1 = (a+b)/2.
If f(x1)=0, then x1 is a root of f(x) = 0, otherwise, the root lies between a
and x1 or x1 and baccording to f(x1) is (+)ve or (-)ve. Then we bisect the inte
rval as before and continue the process until the root is found to the desird ac
curacy. *********/
/*************** PROGRAM STARTS HERE ***************/
#include <stdio.h>
#include <stdlib.h>
@AnuragAnalog
AnuragAnalog / chebysav.py
Created July 10, 2021 02:13
Chebysav method Implementation in python
#!/usr/bin/python3.6
# Chebysav method is like approimating the given Transcedental Equation into a quadratic equation f(x) = 0, f(x) ~ a0 + a1x + a2x^2
#
# Let xk be an approximate root
# f'(x) = a1 + a2x
# f''(x) = 2a2 by subsituting the value xk in all the equations we get the values of f(xk), f'(xk), f''(xk)
# we get,
# f(x) ~ fk + (x-xk)f'_k + (x-xk)^2*f''_k/2 ==> 0
@AnuragAnalog
AnuragAnalog / chebysav.c
Created July 10, 2021 02:18
Chebysav method Implementation in C
/******* Chebysav method is like approimating the given Transcedental Equation into a quadratic equation f(x) = 0, f(x) ~ a0 + a1x + a2x^2
Let xk be an approximate root
f'(x) = a1 + a2x
f''(x) = 2a2 by subsituting the value xk in all the equations we get the values of f(xk), f'(xk), f''(xk)
we get,
f(x) ~ fk + (x-xk)f'_k + (x-xk)^2*f''_k/2 ==> 0
x_(k+1) = xk - fk/f'k - (fk^2 f''_k)/2((f'_k)^3) *********/
@AnuragAnalog
AnuragAnalog / regula-falsi.c
Created July 16, 2021 03:39
Regula Falsi method Implementation in C
/* The bisection method guarantees that the iterative process will converge. It is,
however, slow. Thus, attempts have been made to speed up** the bisection
method retaining its guaranteed convergence. A method of doing this is called
the method of false position.
It is sometimes known as the method of linear interpolation.
This is the oldest method for finding the real roots of a numerical equation
and closely resembles the bisection method.
In this method, we choose two points x0 and x1 such that f(x0) and f(x1) are
of opposite signs. Since the graph of y = f(x) crosses the X-axis between these
two points, a root must lie in between these points.
@AnuragAnalog
AnuragAnalog / muller.c
Created July 17, 2021 02:10
Muller method Implementation in C
/* In Muller, f(x) is approximated by a second degree curve in the vicinity of
a root. The roots of the quadratic are then assumed to be the approximations to
the roots of the equation f(x) = 0.
The method is iterative, converges almost quadratically, and can be used
to obtain complex roots. */
/*************** PROGRAM STARTS HERE ***************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
@AnuragAnalog
AnuragAnalog / free_resume.md
Last active July 6, 2022 03:30
A list of curated websites where you can build you resumes for free of cost
@AnuragAnalog
AnuragAnalog / newton_raphson.c
Created July 18, 2021 09:08
Newton Raphson method Implementation in C
/* This method is generally used to improve the result obtained by one of the
previous methods. Let x0 be an approximate root of f(x) = 0 and let x1 = x0 + h be
the correct root so that f(x1) = 0.
Expanding f(x0 + h) by Taylor’s series, we get
f(x0) + hf′(x0) + h2/2! f′′(x0) + ...... = 0
Since h is small, neglecting h2 and higher powers of h, we get
f(x0) + hf′(x0) = 0 or h = – f(x0)/f'(x0)
A better approximation than x0 is therefore given by x1, where
x1 = x0 - f(x0)/f'(x0)
Successive approximations are given by x2, x3, ....... , xn + 1, where
@AnuragAnalog
AnuragAnalog / newton_raphson.py
Created July 18, 2021 09:11
Newton Raphson method Implementation in Python
#!/usr/bin/python3.6
# This method is generally used to improve the result obtained by one of the
# previous methods. Let x0 be an approximate root of f(x) = 0 and let x1 = x0 + h be
# the correct root so that f(x1) = 0.
# Expanding f(x0 + h) by Taylor’s series, we get
# f(x0) + hf′(x0) + h2/2! f′′(x0) + ...... = 0
# Since h is small, neglecting h2 and higher powers of h, we get
# f(x0) + hf′(x0) = 0 or h = – f(x0)/f'(x0)
# A better approximation than x0 is therefore given by x1, where