mql5/Experts/Examples/Math 3D/Functions.mqh

234 lines
16 KiB
MQL5

2025-08-05 01:57:33 -04:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Functions.mqh |
//| Copyright 2000-2025, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//--- custom function y=f(x,y)
typedef double(*MathFunction)(double, double);
//--- Math functions list
enum EnFunctionType
{
Chomolungma=1,
ClimberDream=2,
Granite=3,
Hedgehog=4,
Hill=5,
Josephine=6,
Screw=7,
DoubleScrew=8,
MultyExtremalScrew=9,
Sink=10,
Skin=11,
Trapfall=12,
};
//+------------------------------------------------------------------+
//| Returns a pointer to a function by its type from FunctionType |
//+------------------------------------------------------------------+
MathFunction GetMathFunction(EnFunctionType type)
{
MathFunction function=ClimberDreamFunction;
switch(type)
{
case Chomolungma:
function=ChomolungmaFunction;
break;
case ClimberDream:
function=ClimberDreamFunction;
break;
case Granite:
function=GraniteFunction;
break;
case Hedgehog:
function=HedgehogFunction;
break;
case Hill:
function=HillFunction;
break;
case Josephine:
function=JosephineFunction;
break;
case Screw:
function=ScrewFunction;
break;
case DoubleScrew:
function=DoubleScrewFunction;
break;
case MultyExtremalScrew:
function=MultyExtremalScrewFunction;
break;
case Sink:
function=SinkFunction;
break;
case Skin:
function=SkinFunction;
break;
case Trapfall:
function=TrapfallFunction;
break;
}
return(function);
}
//+------------------------------------------------------------------+
//| Function Chomolungma |
//+------------------------------------------------------------------+
double ChomolungmaFunction(double x, double y)
{
double a= MathCos(x*x)+MathCos(y*y);
double b= MathPow(MathCos(5*x*y), 5);
double c=1.0/MathPow(2, b);
//--- calculate result
double res=a-c;
return(res);
//---
}
//+------------------------------------------------------------------+
//| Function ClimberDream |
//+------------------------------------------------------------------+
double ClimberDreamFunction(double x, double y)
{
double a= MathSin(MathSqrt(MathAbs(x - 1.3) + MathAbs(y)));
double b= MathCos(MathSqrt(MathAbs(MathSin(x))) + MathSqrt(MathAbs(MathSin(y))));
double f=a+b;
//--- calculate result
double res=MathPow(f, 4);
return(res);
//---
}
//+------------------------------------------------------------------+
//| Function Granite |
//+------------------------------------------------------------------+
double GraniteFunction(double x, double y)
{
double a= MathPow(MathSin(MathSqrt(MathAbs(x)+MathAbs(y))), 2);
double b= MathPow(MathCos(MathSqrt(MathAbs(x)+MathAbs(y))), 2);
//--- calculate result
double res=a*b;
return(res);
//---
}
//+------------------------------------------------------------------+
//| Function Hedgehog |
//+------------------------------------------------------------------+
double HedgehogFunction(double x, double y)
{
double a1=MathSin(MathSqrt(MathAbs(x-2)+MathAbs(y)));
double a2=MathCos(MathSqrt(MathAbs(MathSin(x)))+MathSqrt(MathAbs(MathSin(y))));
//--- calculate result
double res=a1+a2;