Quiet@Remove["Global`*"];

NMinimize[{2 x-3 y,x+y<10,x-y>2,x>1},{x,y}]

LinearProgramming[{2,-3},(({{-1, -1}, {1, -1}, {1, 0}})),{-10,2,1}]

exprToBeMinimized=2x+3y;
constr=(x^2)+(y^2)==1;
rearrangedConstr=constr/.lhs_==rhs_:>lhs-rhs;
Lagrange=exprToBeMinimized+λ*rearrangedConstr;
eqn1=D[Lagrange,x]==0;
eqn2=D[Lagrange,y]==0;
eqn3=D[Lagrange,λ]==0;
sol=Solve[{eqn1,eqn2,eqn3}]
exprToBeMinimized/.sol

Minimize[{exprToBeMinimized,constr},{x,y}]
Maximize[{exprToBeMinimized,constr},{x,y}]

(x^2)/.{{x->2},{x->5}}

object=Table[{i,i+1},{i,10}]
object/.{a_,b_}:>{b,a}

a+b==a-u+y/.lhs_==rhs_:>lhs-rhs

Minimize[{exprToBeMinimized,constr},{x,y}]
Maximize[{exprToBeMinimized,constr},{x,y}]

NMinimize[{exprToBeMinimized,constr},{x,y}]
NMaximize[{exprToBeMinimized,constr},{x,y}]

constr1[var_,varMin_,varMax_,sloop_]:=(2-(Tanh[sloop*(var-varMin)]-Tanh[sloop*(var-varMax)]))*(((var-((varMax+varMin)/2)))^2);
aux=constr1[x,2,4,100];
Plot[aux,{x,-1,7},PlotRange->All];

(*example*)
exprToBeMinimized=x+2y;
con1=2<x<4;
con2=0<y<1;
NMinimize[{exprToBeMinimized,con1,con2},{x,y}]

penaltyX=constr1[x,2,4,1000];
penaltyY=constr1[y,0,1,1000];
F=exprToBeMinimized+100*(penaltyX+penaltyY);
NMinimize[F,{x,y}]

constr2[var_,varMin_,sloop_]:=(1-(Tanh[sloop*(var-varMin)]))*(((var-varMin))^2);
aux=constr2[x,2,100];
Plot[aux,{x,-1,7},PlotRange->All]

(*example DC transm.*)
R1=2;
R2=5;
loses=R1*(i1^2)+R2*(i2^2);
U1=U2=750*(10^3);
P1=(U1-R1*i1)*i1;
P2=(U2-R2*i2)*i2;
Ptotal=1500*(10^6);
NMinimize[{loses,P1+P2==Ptotal},{i1,i2}]

Quiet@Remove["Global`*"];
loses=R1*(i1^2)+R2*(i2^2);
U1=U2=750*(10^3);
P1=(U1-R1*i1)*i1;
P2=(U2-R2*i2)*i2;
Ptotal=1500*(10^6);
Minimize[{loses,P1+P2==Ptotal},{i1,i2}]

Quiet@Remove["Global`*"];

(*Interpolation*)
(*1D interpolation*)
data=Table[{x,Sin[x]},{x,0.,2Pi,(Pi/5)}];
plot1=ListPlot[data,AxesLabel->{"x","Sin[x]"},PlotStyle->{Red,PointSize[0.015]}];
int=Interpolation[data,InterpolationOrder->0];
plot2=Plot[int[x],{x,0,2Pi}];
Show[plot1,plot2]

int=Interpolation[data,InterpolationOrder->1];
plot2=Plot[int[x],{x,0,2Pi}];
Show[plot1,plot2]

(*InterpolationOrder->3 default value*)
int=Interpolation[data,InterpolationOrder->3];
plot2=Plot[int[x],{x,0,2Pi}];
Show[plot1,plot2]

data1=Table[{x,Sin[x]},{x,0.,2Pi,(Pi/50)}];
int=Interpolation[data1,InterpolationOrder->3];
plot2=Plot[int'''[x],{x,0,2Pi}]

data1=Table[{x,Sin[x]},{x,0.,2Pi,(Pi/5)}];
int=Interpolation[data1,InterpolationOrder->3];
plot2=Plot[int[x],{x,0,4Pi}]

data1=Table[{x,Sin[x]},{x,0.,2Pi,(Pi/2)}];
int=Interpolation[data1,InterpolationOrder->3];
TreeForm[int];
{xmin,xmax}=int[[1,1]]

(*more dimensions*)
data2D=Table[{x,y,Sin[x+2y]},{x,0.,2Pi,(Pi/5)},{y,0.,2Pi,(Pi/5)}];
Dimensions[data2D];
data2DForInterpolation=Flatten[data2D,1];
int2D=Interpolation[data2DForInterpolation,InterpolationOrder->{3,3}];
{{xmin,xmax},{ymin,ymax}}=int2D[[1]];
Plot3D[int2D[x,y],{x,xmin,xmax},{y,ymin,ymax},PerformanceGoal->"Quality",PlotPoints->100]

Plot3D[int2D[x,y]-Sin[x+2y],{x,xmin,xmax},{y,ymin,ymax},PerformanceGoal->"Quality",PlotPoints->100]

fUgly[x_]:=x+(Sqrt[1+((Sin[2x])^2)]);
sol[y_]:=x/.FindRoot[fUgly[x]==y,{x,0}];
t1=Timing[Table[sol[y],{y,-3,3,0.001}]][[1]]

dataInverse=Table[{fUgly[x],x},{x,-8,4,0.01}];
solInt=Interpolation[dataInverse];
sol[0.654]-solInt[0.654];
t2=Timing[Table[solInt[y],{y,-3,3,0.001}]][[1]]

(t1/t2)