Help me plot the solution in graph
Afficher commentaires plus anciens
Consider the following system of equations: 9 − 2y − x = 0; −x + 2y = 13.
Use MATLAB to solve the above system of equations. Then, plot the solution and comment on the slope and the shape of the equations.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Réponses (2)
A = randi([-9,9])
B = randi([-9,9])
C = randi([-9,9])
fun1 = @(x,y) A*x + B*y + C
A2 = randi([-9,9])
B2 = randi([-9,9])
C2 = randi([-9,9])
fun2 = @(x,y) A2*x + B2*y + C2
fimplicit(fun1);
hold on
fimplicit(fun2);
hold off
The solution to the system is at the intersection of the two lines.
I'll show you another two ways of plotting the line equations.
syms x y
% specify the two line equations
eqn1 = 9 - 2*y - x == 13; % equation 1
eqn2 = 2*y - x == 0; % equation 2
Method 1: Using ezplot()
yLine1 = isolate(eqn1, y)
yLine2 = isolate(eqn2, y)
figure(1)
h1 = ezplot(yLine1, [-6, 6, -5, 3]);
h1.Color = 'blue'; hold on
h2 = ezplot(yLine2, [-6, 6, -5, 3]);
h2.Color = 'red'; hold off
grid on
title('Method 1: using "ezplot"')
Method 2: Using fplot()
soly1 = solve(eqn1, y)
soly2 = solve(eqn2, y)
figure(2)
fplot(soly1, [-6, 6]), hold on
fplot(soly2, [-6, 6]), grid on
xlabel('x'), ylabel('y')
title('Method 2: using "fplot"')
Catégories
En savoir plus sur Networks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





