Solving constrained linear equation

1 次查看(过去 30 天)
How can I solve the following equation in Matlab?
P1+P2+P3=370
I need to see all the P1,P2,P3 values that satisfy equation with this constraints:
100<P1<270
0<P2<270
0<P3<100
The range of change of P1, P2 and P3 is 10 units. (P1=100:10:270;P2=0:10:270;P3=0:10:100;)
Thanks

采纳的回答

John D'Errico
John D'Errico 2017-8-16
编辑:John D'Errico 2017-8-16
There are infinitely many solutions. If you need to generate all of them, get some coffee.
So you cannot "solve" that equation. There is a 2-dimensional locus of solutions, thus a polygonal planar region all points, all of which lie in a plane.
But worse, the region is not even a closed set. It does not include all the boundary points, due to your use of strict inequalities on the parameters. For example, because you specified 0<P2, P2==0 is never part of a solution, but there is a point with P2 == 0 that is one of the vertices of the polygon that would contain your solutions.
But SOME (and ONLY SOME) points on the boundary of the polygon are included. So it is a partially closed set.
So again, you cannot compute all solutions. And your use of < here for the inequalities makes the problem subtly more difficult. You could in theory, display the solution locus in a 3-d plot, IF you were to change the < to <= inequalities.
  3 个评论
Babak
Babak 2017-8-16
There is one more thing. Because the step change is 10 (P1=100:10:270), I think there are limited answers for this problem!!
John D'Errico
John D'Errico 2017-8-16
编辑:John D'Errico 2017-8-16
Generate the corners of the polygon. There are only a few such corners. For example:
with P1=100, we have P2=270 and P3=0. So the point [100 270 0] is a vertex.
Similarly, [100 170 100] is another vertex of the polygon. We can continue in this vein, finding vertices at [270 0 100], [270 100 0].
Thus so far, the list of vertices is:
V = [100 270 0;
100 170 100;
270 0 100;
270 100 0]
Are there others? Consider when P2 lies at its limits. When P2=0, we have already identified the point [270 0 100]. When P2=270, we have the point [100 270 0], which again is already in the list.
Finally, when P3 lies at its limits, I think you will find that there are two vertices, already identified.
So the solution locus is a quadrilateral, that lies in an inclined plane. You can just use patch to plot the region.
As far as the discrete nature of the problem, it is coarse enough that brute force will suffice.
[P1,P2,P3] = ndgrid(100:10:270,0:10:270,0:10:100);
ind = P1 + P2 + P3 == 370;
P123 = [P1(ind),P2(ind),P3(ind)];
I can use an exact test for equality here, because they are all exact integers.
size(P123)
ans =
198 3
So the coarse discrete set comprises 198 solutions. You can plot them all using plot3. It should be no surprise they will lie in a quadrilateral.
plot3(P123(:,1),P123(:,2),P123(:,3),'o')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Chemistry 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by