Graphing a hyperbola and its tangent lines

3 vues (au cours des 30 derniers jours)
mdawg22
mdawg22 le 9 Mar 2020
Hello I am trying to graph a hyperbola along with a tangent line.
The tangent line must have an x value of x=(8.9) I want matlab to calculate the y value at this point, and than i want to plot it.
Here is my code so far, note that the first value is just a test tangent line.
Everytime I attempt to graph at the point x = 8.9 i simply just get the same graph, nothing changes.
Any suggestions?
syms x y;
F(x,y) = 2*y-3*x-3*x*y+x^2+y^2-6; %This is my hyperbola
F(1.948,1.063) %This is my test tangent line
Fx(x,y) =diff(F,x); Fy(x,y) = diff(F,y);
m1 = Fx(1.948,1.063); m2 = Fy(1.948,1.063);
fimplicit(m1*(x-1.948) + m2*(y-1.063) == 0, [-10,10], '-b', 'LineWidth', 3);
hold on;
fimplicit(F == -11.005, [-100,100], '-r', 'LineWidth', 3);
hold off;
assume(y, 'real');
xPt = 8.9; %This is the point i would like to graph a tangent line at
yPts = double(solve(F(xPt, y) == -11.005, y))
yPt1 = yPts(1); yPt2 = yPts(2)
mx1 = double(Fx(xPt, yPt1)); my1 = double(Fy(xPt, yPt1)); mx2 = double(Fx(xPt, yPt2)); my2 = double(Fy(xPt, yPt2));
fimplicit(m1*(x-1.948) + m2*(y-1.603) == 0, [-10,10], '-b', 'LineWidth', 3);
hold on;
fimplicit(mx1*(x-xPt) + my1*(y-yPt1) == 0, [xPt - 0.1, xPt+0.1, yPt1 - 0.5, yPt1+0.1], '-r', 'LineWidth', 3);
fimplicit(mx2*(x-xPt) + my2*(y-yPt2) == 0, [xPt - 0.1, xPt+0.1, yPt2 - 0.5, yPt2+0.1], '-g', 'LineWidth', 3);
fimplicit(F == -11.005, [-100,100], '-k', 'LineWidth', 3);
hold off;

Réponses (1)

Christopher Creutzig
Christopher Creutzig le 9 Mar 2020
Your tangent lines are very short, and you plot the hyperbola right on top of them. Change the order, increase the size, and they become visible:
fimplicit(m1*(x-1.948) + m2*(y-1.603) == 0, [-10,10], '-b', 'LineWidth', 3);
hold on;
fimplicit(F == -11.005, [-100,100], '-k', 'LineWidth', 3);
fimplicit(mx1*(x-xPt) + my1*(y-yPt1) == 0, [xPt - 10, xPt+10, yPt1 - 10, yPt1+10], '-r', 'LineWidth', 3);
fimplicit(mx2*(x-xPt) + my2*(y-yPt2) == 0, [xPt - 10, xPt+10, yPt2 - 10, yPt2+10], '-g', 'LineWidth', 3);
hold off;

Community Treasure Hunt

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

Start Hunting!

Translated by