I have a non linear function with 3 variables and 4 linear constraint inequalities. I want get values of three variables with minimizing non linear function using Least square method.
creating function file
function f=objfun(x)%%%longitudinal velocities %%%
rho=8.96e-3;voigtl=sqrt((((x(1)+2*x(2))/3)+((4/15)*(x(1)-x(2)+3*x(3))))/rho);reussl=sqrt((((x(1)+2*x(2))/3)+((4/3)*(5*x(3)*(x(1)-x(2))/(3*(x(1)-x(2))+4*x(3)))))/rho);velham=(voigtl+reussl)/2;%%longitudinal velocity as per Hill criterion in arithmetic mean
velhgm=sqrt(voigtl*reussl);%%longitudinal velocity as per Hill criterion in geometric mean
velexp=4854; %%experimentally measured velocity
f=((velham)^2-(velexp)^2)/(velexp)^2;end
creating contraints
function [c, ceq] = confun(x) % Nonlinear inequality constraints
c = [-x(1)-2*x(2); -x(3);-x(1)+x(2);((x(1)-x(2))/2)-x(3)]; % Nonlinear equality constraints
% Nonlinear equality constraintsceq = [];end
minimizing function used
x0 = [1,1,1]; % Make a starting guess at the solution
options = optimset('TolFun',1e-10,'MaxIter',4000);% A=[-1,-2,0; 0,0,-1; -1,1,0; 1/2,-1/2,-1;];
% b=[0,0,0,0];
lb=[50,50,50];ub=[];[x,fval,iterations] = quadprog(@objfun,x0,[],[],[],[],[],[],@confun,options);
Best Answer