Skip to content

Instantly share code, notes, and snippets.

@ryangmolina
ryangmolina / fuzzy_logic.py
Created June 16, 2017 13:26
A simple python implementation of Mamdani Fuzzy Logic
def trimf(x, points):
pointA = points[0]
pointB = points[1]
pointC = points[2]
slopeAB = getSlope(pointA, 0, pointB, 1)
slopeBC = getSlope(pointB, 1, pointC, 0)
result = 0
if x >= pointA and x <= pointB:
result = slopeAB * x + getYIntercept(pointA, 0, pointB, 1)
elif x >= pointB and x <= pointC:
@bmccormack
bmccormack / movingAvg.c
Created March 31, 2015 01:05
Moving average example in C
#include <stdio.h>
int movingAvg(int *ptrArrNumbers, long *ptrSum, int pos, int len, int nextNum)
{
//Subtract the oldest number from the prev sum, add the new number
*ptrSum = *ptrSum - ptrArrNumbers[pos] + nextNum;
//Assign the nextNum to the position in the array
ptrArrNumbers[pos] = nextNum;
//return the average
return *ptrSum / len;