Solving system of Non-linear Equations graphically

Problem Statement: I want to solve a set of equations graphically by plotting their graphs and looking at the interesection. I know how to solve a linear system of equations in 2D, like this.
%Simulataneous Equations
%3x1+2x2 =10
% 2x1 - x2 =2
%Graphical Solution
x= 0:0.1:10;
x1 = (1/3).*(18-2.*x);
x2= -2 + 2.*x;
plot(x,x1,'r')
hold on
plot (x,x2,'b');
grid on
xlabel('x1')
ylabel('x2')
Now I want to do a similar thing but for a set of equations with two variables instead of one. The equations are
I want them to plot like I could for above example and see their intersection. I know second equation is just a constant and hence i expected a plane passing through the value 5.
My attempt:
% Making an vector for input variable
x1_1= linspace(0,20);
y1_1=ones(1,100)*5;
%making a grid
[x1_1,y1_1] = meshgrid(x1_1,y1_1);
%The third equation of the set
z1_1= (1 + x1_1.*y1_1)./(x1_1+x1_1^2);
%making a vector for other plot
y1_2=ones(1,100)*5;
z1_2 = linspace(0,20);
%making a grid
[y1_2,z1_2] = meshgrid(y1_2,z1_2);
x1_2= 1+y1_2-z1_2;
% Plotting for 3D graph.
surf(x1_1,y1_1,z1_1);
hold on
surf(x1_2,y1_2,z1_2);
I did not do for the third equation but all I get are two lines instead of two planes intersecting at some point. If any help or a small hint with the code can be provided, i would be thankful to you.
Thank you.

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 23 de Abr. de 2020
try this
figure;
ax = axes();
view(3);
hold(ax);
% First equation
x1 = linspace(-20,20);
y1 = linspace(-20,20);
%making a grid
[x1,y1] = meshgrid(x1,y1);
%The third equation of the set
z1= 1 + y1 - x1;
surf(ax, x1, y1, z1, 20*ones(size(x1)));
% Second equation
x1 = linspace(-20,20);
z1 = linspace(-20,20);
[x1,z1] = meshgrid(x1,z1);
y1 = 5*ones(size(x1));
surf(ax, x1, y1, z1, 10*ones(size(x1)));
% Third equation
x1 = linspace(-20,20);
y1 = linspace(-20,20);
%making a grid
[x1,y1] = meshgrid(x1,y1);
%The third equation of the set
z1= (1 + x1.*y1)./(x1+x1.^2);
surf(ax, x1, y1, z1, 1*ones(size(x1)));
zlim([-20 20])
legend({'Eq1', 'Eq2', 'Eq3'})

6 comentarios

Thanks for the solution Ameer. Using your solution to the problem, I tried it on this set of equations but couldn't get the correct graph. I didn't wanted you to spoon feed me everything, hence i was trying for the solution, but couldn't reach it. Even a little hint would be helpful.
K=0.03166;
alpha=0.001281;
r= 0.00173;
A0=0.4;
gammaA=0.04;
gammaI= 0.0208;
alpha1= 1.30187;
c1= 0.63433;
rho= 0.95103;
eps= 0.00055;
figure;
ax = axes();
view(3);
hold(ax);
% First equation
x1 = linspace(0,20);
y1 = linspace(0,20);
%making a grid
[x1,y1] = meshgrid(x1,y1);
%The first equation of the set
z1= K*(1+ (alpha/r)*y1 -(eps/r)*x1);
surf(ax, x1, y1, z1, 20*ones(size(x1)));
% Second equation
x1 = linspace(0,1);
z1 = linspace(0,20);
[x1,z1] = meshgrid(x1,z1);
y1 = 10*ones(size(x1));
surf(ax, x1, y1, z1, 10*ones(size(x1)));
% Third equation
x1 = linspace(0,1);
y1 = linspace(0,20);
%making a grid
[x1,y1] = meshgrid(x1,y1);
%The third equation of the set
z1=(0.3* (alpha+ x1))./(c1*alpha1*x1 + c1*x1.^2 + gammaI*alpha1 + gammaI*x1 -rho*x1);
surf(ax, x1, y1, z1, 1*ones(size(x1)));
zlim([0 20])
legend({'Eq1', 'Eq2', 'Eq3'})
Something similar to this i was expecting.
The equations were:
Thanks .
Compared to the image you posted, the closest I have got is something like the following code. The places of 1st and 2nd equation looks similar to the image, but for the 3rd equation, parameter need to be tuned to look like this
K=0.03166;
alpha=0.001281;
r= 0.00173;
A0=0.4;
gammaA=0.04;
gammaI= 0.0208;
alpha1= 1.30187;
c1= 0.63433;
rho= 0.95103;
eps= 0.00055;
figure;
ax = axes();
view(3);
hold(ax);
colormap(ax, [1 0 0; 0 1 0; 0 0 1]);
ax.CLim = [1 3];
% First equation
y1 = linspace(0, 20, 10);
z1 = linspace(0, 20, 10);
%making a grid
[y1, z1] = meshgrid(y1, z1);
%The first equation of the set
x1 = K*(1 + (alpha/r)*y1 - (eps/r)*z1);
surf(ax, x1, y1, z1, 1*ones(size(x1)));
% Second equation
x1 = linspace(0, 1, 10);
z1 = linspace(0, 20, 10);
[x1, z1] = meshgrid(x1, z1);
y1 = 10*ones(size(x1));
surf(ax, x1, y1, z1, 2*ones(size(x1)));
% Third equation
x1 = linspace(0, 1, 10);
y1 = linspace(0, 20, 10);
% making a grid
[x1, y1] = meshgrid(x1, y1);
%The third equation of the set
z1 = (0.3*(alpha + x1))./(c1*alpha1*x1 + c1*x1.^2 + gammaI*alpha1 + gammaI*x1 - rho*x1);
surf(ax, x1, y1, z1, 3*ones(size(x1)));
daspect([0.3 1 1])
xlim([0 1])
ylim([0 20])
zlim([0 20])
xlabel('x');
ylabel('y');
zlabel('z');
legend({'Eq1', 'Eq2', 'Eq3'})
Vira Roy
Vira Roy el 24 de Abr. de 2020
Thanks Ameer Hamza for all your help. It is so appreciated. I am accepting the your answer.
Thank you.
Ameer Hamza
Ameer Hamza el 25 de Abr. de 2020
I am glad that my comments were helpful to you.
Vira Roy
Vira Roy el 25 de Abr. de 2020
I managed to get the correct graph from your help Ameer. Just a final remark. can I know the intersection point as well.
Thanks...
Ameer Hamza
Ameer Hamza el 25 de Abr. de 2020
For that, you will need to use fsolve().

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Preguntada:

el 22 de Abr. de 2020

Comentada:

el 25 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by