Jul-30-2021, 06:47 AM
Hi guys, i've been investigating this article..
Article 1: Unidimensional Search Scheme Using Identric Mean for Optimization Problems
Article 2: A NEW UNIDIMENSIONAL SEARCH METHOD FOR OPTIMIZATION
I developed the code based on article 1, but I can't develop the code based on article 2. I don't understand how to solve the RMS method to solve the equations
What I need is to solve the example equations with the methods of the articles and compare their results.
Can you help me with the code for the second article?
CODE Article 1:
Article 1: Unidimensional Search Scheme Using Identric Mean for Optimization Problems
Article 2: A NEW UNIDIMENSIONAL SEARCH METHOD FOR OPTIMIZATION
I developed the code based on article 1, but I can't develop the code based on article 2. I don't understand how to solve the RMS method to solve the equations
What I need is to solve the example equations with the methods of the articles and compare their results.
Can you help me with the code for the second article?
CODE Article 1:
from math import exp from sympy import * def identricmean(function, A, B, tol=1e-4): def fun(x): if (len(function) > 1): for i in range(len(function)): if (function[i] == "<" and x < float(function[i + 1])): value = eval(function[i - 1]) elif (function[i] == ">" and x > float(function[i + 1])): value = eval(function[i - 1]) elif (function[i] == ">=" and x >= float(function[i + 1])): value = eval(function[i - 1]) elif (function[i] == "<=" and x <= float(function[i + 1])): value = eval(function[i - 1]) elif (function[i] == "=" and x == float(function[i + 1])): value = eval(function[i - 1]) else: value = eval(function[0]) return value k = 0 A = A C = B B = (A + C) / 2 fA = fun(A) fC = fun(C) fB = fun(B) S = 1 / exp(1.0) * ((A ** A / C ** C)) ** (1 / (A - C)) fS = fun(S) while True: k += 1 fB = min(fA, fB, fC, fS) list = sorted([A, B, C, S]) for i in range(len(list)): if fB == fun(list[i]): B = list[i] A = list[i - 1] if (len(list) > i + 1): C = list[i + 1] break D = 1 / exp(1.0) * ((A ** A / C ** C)) ** (1 / (A - C)) fD = fun(D) if abs((fS - fD) / fS) <= tol: f_min = min(fB, fS, fD) list_2 = sorted([S, B, D]) for i in range(len(list_2)): if f_min == fun(list_2[i]): x_min = list_2[i] break else: S = D fS = fD return x_min, f_min # Example 1 A = 3 B = 2 tol = 1e-3 ans = identricmean(["x**5-5*x**3-20*x+5"], A, B, tol) print("Example 1: ", ans) # Example 2 A = 0 B = 15 ans = identricmean(["x**4-8.5*x**3-31.0625*x**2-7.5*x+45"], A, B, tol) print("Example 2: ", ans) # Example 3 A = 2 B = 1 ans = identricmean(["5*(x-0.8)**2 + 1", "<", "0.8", "100*(x-0.8)**2 + 1.0", ">=", "0.8"], A, B, tol) print("Example 3: ", ans)