Filter löschen
Filter löschen

Solving system of Non-linear Equations graphically

12 Ansichten (letzte 30 Tage)
Vira Roy
Vira Roy am 22 Apr. 2020
Kommentiert: Ameer Hamza am 25 Apr. 2020
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.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 23 Apr. 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 Kommentare
Vira Roy
Vira Roy am 25 Apr. 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 am 25 Apr. 2020
For that, you will need to use fsolve().

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by