%% 3D Plot of Multivariable System of Equations
%% 1

syms x y z
eqn1 = z == 10*(cos(x) + cos(y));
eqn2 = z == x+y^2-0.1*x^2*y;
eqn3 = x+y-2.7 == 0;
equations = [eqn1 eqn2 eqn3];
fimplicit3(equations)
axis([0 2.5 0 2.5 -20 10])
title('System of Multivariate Equations')
view(69, 28)
caxis([-15 10])

%
%% 2

sol = vpasolve(equations);
[sol.x sol.y sol.z]

%
%% 3

vars = [x y z];
range = [0 1.5; 1.5 2.5; NaN NaN];
sol = vpasolve(equations, vars, range);
[sol.x sol.y sol.z]

%
%% 4

clear sol
range = [0 3; 0 3; NaN NaN];
for i = 1:5
    temp = vpasolve(equations, vars, range, 'random', true);
	sol(i,1) = temp.x;
    sol(i,2) = temp.y;
    sol(i,3) = temp.z;
end
sol

%
%% 5

clf
ax = axes;
h = fimplicit3(equations);
h(2).FaceAlpha = 0;
h(3).FaceAlpha = 0;
axis([0 2.5 0 2.5 -20 10])
hold on
scatter3(sol(:,1),sol(:,2),sol(:,3),600,'yellow','X','LineWidth',2)
title('Randomly found solutions in specified search range')
cz = ax.Children;
caxis([0 20])
view(69,28)
hold off

% Copyright 2012 The MathWorks, Inc.