Help me plot the solution in graph

4 vues (au cours des 30 derniers jours)
Hung
Hung le 27 Sep 2023
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)

Walter Roberson
Walter Roberson le 27 Sep 2023
A = randi([-9,9])
A = -8
B = randi([-9,9])
B = -4
C = randi([-9,9])
C = -5
fun1 = @(x,y) A*x + B*y + C
fun1 = function_handle with value:
@(x,y)A*x+B*y+C
A2 = randi([-9,9])
A2 = 1
B2 = randi([-9,9])
B2 = 7
C2 = randi([-9,9])
C2 = -1
fun2 = @(x,y) A2*x + B2*y + C2
fun2 = function_handle with value:
@(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.

Sam Chak
Sam Chak le 27 Sep 2023
Hi @Hung,
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)
yLine1 = 
yLine2 = isolate(eqn2, y)
yLine2 = 
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)
soly1 = 
soly2 = solve(eqn2, y)
soly2 = 
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 Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by