How to set symbolic constratins when solving a system of equations?
3 次查看(过去 30 天)
显示 更早的评论
Hi, I'm trying to solve an under-determined system of equations where I set a non-scalar constraint based on the values of other variables.
It appears that the functions available only accept upper and lower bounds as scalar inputs. However I need to set my constraints based on the variables, as shown below, with a simplified example where I've set up and equation expecting x=[3,2,1] as a potential solution.
Please note that due to the nature of how my actual system of equations are based on other variables, I have to set it up in a symbolic form before converting them into a function handle.
x=sym('x',[3 1]);
% Set up system of equations
eqn(1)=x(1)+x(2)+x(3)-6;
eqn(2)=x(1)+2*x(2)+x(3)-8;
% Set Constraints
eqn(3)=x(3)>0;
eqn(4)=x(3)<10;
eqn(5)=x(2)>x(3);
eqn(6)=x(2)<x(3)*5;
eqn(7)=x(1)>x(2);
eqn(8)=x(1)<x(2)*5;
% Find a solution
fun=matlabFunction(eqn);
f=sym('f',[3 1]);x0=ones(1,3);
funMiddleMan = @(f) fun(f(1),f(2),f(3));
[sol] = fsolve(funMiddleMan,x0);
I am able to produce a solution without including the constraints, but when I include them I'll get the error message below:
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
> In fsolve (line 298)
No solution found.
fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
default value of the function tolerance.
<stopping criteria details>
sol =
0.9948 2.0000 3.0052
Even
sol=vpasolve(eqn)
Produces no solutions
Would you please help me with this? Thank you very much!
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!