-1

My question is, using the below functions, how can I numerically find the optimized values of USL and LSL so that the return value of the function Pythag is at a global minimum (i.e. the gradient of Pythag == 0) while somehow tethering Cp and Cpk so that Cp returns the value 2 and Cpk returns the value of 1.5.(Cp==2 and Cpk==1.5)

import numpy as np
import matplotlib.pyplot as plt


def Cp(USL,LSL,s):
    return (USL-LSL)/(6*s)

def Cpk(USL,LSL,mean,sd):
    return min((USL-mu)/(3*s),(mu-LSL)/(3*s))

def Pythag(USL,LSL):
    return np.sqrt(np.square(USL)+np.square(LSL))

#This code below is for practice data 
x = np.linspace(0,100,101)
y = np.random.random(101)
sd = np.std(y)
mu = np.mean(y)

Please let me know if further clarification is needed. Thanks for your question Rory, I've added some key changes above so the question makes more sense. The reason that the other answers to similar questions were not sufficient is because I'm having a difficult time integrating them with the min parameter on the Cpk function.

Todd Muller
  • 11
  • 2
  • 7
  • What have you tried? For example, have you done a web search on "minimization Python" or "optimization Python"? If so, why were the results not suitable for you? Is there something in particular you did not understand? Also, you ask to minimize `Pythag` but that function does not call `Cp` or `Cpk`, so what is the purpose of those functions and of the four lines at the bottom of your code? As it is now, the minimum of `Pythag` is at `USL=0` and `LSL=0`. – Rory Daulton Jul 16 '18 at 19:14

1 Answers1

0

This is what I found, probably a better way but it works

def six_sigma(USL,LSL,s,mean):

def Cp(USL,LSL,s):
    return (USL-LSL)/(6*s)

def Cpk(USL,LSL,s,mean):
    return min([(USL-mean)/(3*s),(mean-LSL)/(3*s)])


Cp = Cp(USL,LSL,s)
Cpk = Cpk(USL,LSL,s,mean)
return (Cp,Cpk)


def USL_LSL_solver(s,mean):
    LSL = mean; USL=mean
    for i in range(1000):
        x,y = six_sigma(USL,LSL,s,mean)
        USL-=x-1.5
        LSL+=y-1
    return (USL,LSL)

USL,LSL = USL_LSL_solver(std,mu)
print(Pythag(USL,LSL))
Todd Muller
  • 11
  • 2
  • 7