Solve function not working for linear equation system with symbolic variables
Show older comments
I have set up a system of linear equations (admittedly complicated) that represent planes.
if true
% function [S] = planefinder(N)
P1 = [];
P2 = [];
P3 = [];
T = [];
for j = 1:size(N,1)
P1 = [N(j,1),N(j,2),N(j,3)];
P2 = [N(j,4),N(j,5),N(j,6)];
P3 = [N(j,7),N(j,8),N(j,9)];
normal = cross(P1-P2, P1-P3);
syms x y z
P = [x,y,z];
planefunction = dot(normal, P-P1);
T = [T, planefunction==0];
end
S = solve(T);
end
'T' does indeed give me a system of 32 planes. However, instead of a numerical or implicit solution in terms of x,y,z I just get the following ouput:
if true
x: [0x1 sym]
y: [0x1 sym]
z: [0x1 sym]
end
I am not sure what this represents; another user on a different thread with a similar problem found that a reinstall of the symbolic math package solved the problem. Is this what I need to do, and is what I've tried with solve() a method that would work? Another obvious function to try would be linsolve, but I don't know a simple way to rearrange my equations (which are of the form a*x + b*y + c*z - d ==0) so that I get a vector of the d coefficients on the right hand side. Thanks in advance.
Hi John,
I have an update on my attempt to tackle this problem. I am using a function which was written by somebody else, called ConvexPolytrope.m- attached.
This works out the convex shape that bounds half-spaces (not planes as I said before).
The input to this code as you can see is a matrix where each row is the coefficients of the half-space equation, plus an 'inner point' which the algorithm needs as a starting point.
So, in the end, I have 8 planes to which the polytrope is a solution. 2 of these define the half spaces- they are defined by my original problem.
Then there are 6 half spaces- it is simplest to choose these to be the faces of a cuboid, where one of the variables in the plane system has it's lower/upper bound.
I do this, and I am pretty sure my set of half planes is consistently defined. However, with the following input, which is supposed to be the 6 'bounding planes',
convexPolytrope([0,-1,0,-2500; 0,1,0,-2000; 0,0,-1,-50; 0,0,1,-25; -1,0,0,-2500; 1,0,0,-2000;],[0.5,0.5,0.5])
I get the same kind of output that I originally posted about
ans = [4x3 double] [4x3 double] [4x3 double] [4x3 double] [4x3 double] [4x3 double]
It's worse if I additionally supply the two planes,
convexPolytrope([1,1,-1,0; 1,0,-1,0; 0,-1,0,-2500; 0,1,0,-2000; 0,0,-1,-50; 0,0,1,-25; -1,0,0,-2500; 1,0,0,-2000;],[-0.5 -0.5 -0.5])
Error using cgprechecks (line 30) Data points containing Inf or NaN are not supported.
Error in convhulln (line 41) cgprechecks(x, nargin, cg_opt);
Error in convexPolytrope (line 38) K = convhulln(G);
What is wrong with my input that could produce the 'NaN or 'Inf' error?
convexPolytrope.m
Matthew Worsdale
Accepted Answer
More Answers (1)
Matthew Worsdale
on 3 May 2015
0 votes
2 Comments
John D'Errico
on 3 May 2015
Ok. so you have 32 planes that you want to solve for. Are you sure it is only 32? nchoosek(8,3) = 56. So there are 56 possible ways to choose 3 out of 8 points, thus 56 possible planes given 8 points.
Regardless, I'm not sure what you mean by a "convex polytope that bounds a set of planes". Planes are infinite in extent.
Part of me is wondering if your goal is simply the convex hull of your original set of 8 points. So please explain more. I'm pretty sure there is a simple solution to this, once I understand your goal.
Matthew Worsdale
on 7 May 2015
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!