Solving n x m non-linear equation systems where n > m
Show older comments
Hi all,
I am trying to solve m-nonlinear equations with n-unknowns. keeping in mind that n > m. What is the best way to do that using matlab?
My idea was to use "GlobalSearch" or "fsolve" functions in optimization toolbox matlab 2013b. the following is true for the problem in hand:
- m = 2 & n = 4
- f(x) = [@(x) (x(1)*cos(x(2)) - a*x(3) + b*x(4)) ; @(x) (x(1)*sin(x(2)) -b*x(3) + a*x(4))]
- x(1),x(2),x(3),x(4) are the 4 unknowns variables in the equation
- a,b are vectors of values that change with time.
- The answer of those two equations is [y1,y2] which are vectors of values that change with time depending on a,b values.
from above this means that for variables a,b,y1,y2 at index "i" the equations will look like the follwoing:
f1(x) = y1(i) = x(1)*cos(x(2)) - a(i)*x(3) + b(i)*x(4)
f2(x) = y2(i) = x(1)*sin(x(2)) - b(i)*x(3) + a(i)*x(4)
the follwoing constraints applys:
- 0<= x(1) <= ((30e3*sqrt(2))+((30e3*sqrt(2))/2))
- -2*pi <= x(2) <= 2*pi
- 0<= x(3) <= inf
- -inf <= x(4) <= inf
rng default % For reproducibility
lb = [0,-2*pi,0,-inf];
ub = [30e3*sqrt(2),2*pi,inf,-inf];
X0 = rand(4,1);
% Lets assume i = 500 and get the values at that index of our vectors
y1 = 2.4480e+04
y2 = -5.2580
a = -0.1333
b = 0.2775
Test.a = a;%OptimIn.a(iha);
Test.b = b;%OptimIn.b(iha);
Test.y1 = y1;%OptimIn.y1(iha);
Test.y2 = y2;%OptimIn.y2(iha);
GlobalSearch_Test.gs = GlobalSearch;
% for writing the Objective function i am not sure how to do it:
% I have the follwoing in general:
% Y = f(X,a,b); where Y = [y1;y2] and X = [x(1);x(2);x(3);x(4)]
% and i want to minimize the residual so:
% ß = min x sum(Y- f(X)); the sum is between i = 1 to i = end
GlobalSearch_Test.MyObj = @(x) ((x(1))^2 + (x(2))^2);% I am not sure what should the objective function be i want to minimize the residuales of the solution of those two equations
GlobalSearch_Test.c = @(x)[x(1)*cos(x(2)) - Test.a*x(3) + Test.b*x(4) - Test.y1;
x(1)*sin(x(2)) - Test.b*x(3) + Test.a*x(4) - Test.y2];
GlobalSearch_Test.nonlinfcn = @(x)deal(GlobalSearch_Test.c(x));
GlobalSearch_Test.problem = createOptimProblem('fmincon','x0',X0,...
'objective',GlobalSearch_Test.MyObj,'lb',lb,'ub',ub,...
'nonlcon',GlobalSearch_Test.nonlinfcn);
GlobalSearch_Test.problem.options.TolCon = 1.0000e-50;
GlobalSearch_Test.x = run(GlobalSearch_Test.gs,GlobalSearch_Test.problem);
%% or the other method i tried is:
% but i dont consider this the best way as i am not allowed to but limits for my search for optimal solution.
OptimIn.f = @(x) [(x(1)*cos(x(2)) - OptimIn.a*x(3) + OptimIn.b*x(4) - OptimIn.y1); (x(1)*sin(x(2)) - OptimIn.b*x(3) + OptimIn.a*x(4) - OptimIn.y2)];
OptimIn.X0 = rand(4,1);%zeros(4,1);%ones(4,1);
%OptimIn.Options = optimoptions('fsolve','Display','iter-detailed');
OptimIn.Options = optimset('Display','iter-detailed','TolFun',1e-50,'TolX',1e-50);
[Optim.X,Optim.fval,Optim.exitflag,Optim.output,Optim.jacobian] = fsolve(OptimIn.f,OptimIn.X0,OptimIn.Options);
so can you tell me what is the best way to solve such problem?
best regards
Accepted Answer
More Answers (0)
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!