MATLAB Answers

Plotting a pair of linear equations to display a graph showing the solution of a pair of simultaneous equations that my program solves.

7 views (last 30 days)
Hello fellow users. I would like to know how to plot a par of linear equations to display a graph showing the solution of a pair of simultaneous equations that my program solves. Note: The equations are in the form : x1*X + y1*Y = z1 x2*X + y2*Y = z2. The user is prompted to enter these values (x1,y1,z1,x2,y2,z2) hence determining the equations. A plot of the 2 equations showing where the 2 lines interecept ( solution calculated by program) would be a nice addition to the program. Any help is aprreciated and thank you in adnvance.

  0 Comments

Sign in to comment.

Accepted Answer

KSSV
KSSV on 9 Jul 2020
  1. Read about input to make the user to enter the results. (I would prefer straight away values)
  2. If A is a 2X2 matrix and b is 2*1 matrix...you have Ax = b. This can be solved using "\". Read about it.
  3. To plot, you can take some x range (xmin,xmax)..substitue it in the striaght line equation (ax+by=c) and get y. Use plot(x,y) to plot it.
  4. To get intersection, you can follow general coordinate geometry intersection of lines method. https://byjus.com/point-of-intersection-formula/

  1 Comment

Michael Gangaram
Michael Gangaram on 9 Jul 2020
Thank you very much. i have managed to solve it using tip 3. tip 4 was also helpful however i will just use the solution generated by the program. tips 1 and 2 were completed already however instead of the matrices method substitution and elimination were used. Here is the code i used to solve this. (a,b,c,a2,b2,c2 are user inputs in my case but instead of clipping the entire program i made this snippet for simplicity).Thanks again.
x = -10:0.01:10;
a = 2;
b = 4;
c = 6;
y = (-a*x + c)/b;
plot(x,y)
hold on;
a2 = 6;
b2 = 8;
c2 = 10;
y2 = (-a2*x + c2)/b2;
plot(x,y2)
Ax = gca;
Ax.YAxisLocation = 'origin';
ylim([0 20]);

Sign in to comment.

More Answers (0)