Plotting graph with only one point (x,y) and slope
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Here is the equation of the curve:
(y2-y1)=m(x2-x1)+c
I have the value of x1, y1, y2 and the slope, and I am trying to get the value of x2 from the graph which correspond to y2, in order to solve for c. How should I write the code to plot the graph on matlab?
0 Kommentare
Antworten (1)
Star Strider
am 15 Okt. 2020
A bit of algebra (courtesy of the Symbolic Math Toolbox to prevent stupid errors, that I will let you re-derive if you wish) makes the calculation straightforward:
x1 = rand;
y1 = rand;
y2 = rand;
m = rand;
B = [(y2 - y1 + m*x1)/m; y1 - m*x1];
figure
plot([x1 B(1)], [y1, y2], '-b')
hold on
plot(B(1), y2, 'p')
plot(0, B(2), 'p')
hold off
grid
axis([0 max(xlim)*1.1 0 max(ylim)*1.1])
text(0.3, 0.1, sprintf('$Calculated Slope\\ \\ \\frac{y2-y1}{x2-x1} = %.3f$', (y2-y1)/(B(1)-x1)), 'Interpreter','latex')
text(B(1), y2, '\leftarrow x_2', 'HorizontalAlignment','left', 'VerticalAlignment','middle')
text(0, B(2), '\leftarrow c', 'HorizontalAlignment','left', 'VerticalAlignment','middle')
Obviously use your own values for the variables.
0 Kommentare
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!