Solving n x m non-linear equation systems where n > m
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Bjorn Gustavsson
2020-8-20
If you look at your equations, you can rewrite them (as far as I understand) to:
This you can treat as a linear system in x(3) and x(4) that you can solve explicitly then since the right-hand-side are variable with some limits on x(1) and x(2) this will correspond to 2 surfaces for x(3) and x(4). Here it might be best to explicitly calculate the inverse of your left-hand-side matrix just to multiply it with the right-hand-side-vector in order to get the explicit equations for the surfaces. Once you've done that you can evaluate that for all your values of interest. Since you want to calculate the surfaces for a -mesh it is easier (IMO) to do the explicit calculations of the matrix inverse and multiplication with the RHS - that way you get 2 simple expressions for x3 and x4 that you can easily calculate and display with for example pcolor.
HTH
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!