Drawing a tangent line on plot but keep getting the error "array indices must be positive integers or logical values"?

1 visualizzazione (ultimi 30 giorni)
I have a plot and I picked two points from that plot that I need to use to draw a tangent line.
After choosing the points, I used them to find the slope and then changed it to slope intercept form to find the y value. Then I plotted it.
Here is my code:
%original plot
plot(X1,Y1)
%picking points
x1=3.4959;
y1=1925.72;
x=14.214;
y=8113.27;
%slope formula
k=(y-y1)/(x-x1);
y=k(x-x1)+y1; %this is the line giving me the error
hold on
plot(x,y);
hold off
Why doesn't this work? I was told to compute the slope and then use y-y1=k(x-x1) to draw the line. What did I do wrong?

Risposte (1)

Cris LaPierre
Cris LaPierre il 18 Nov 2020
You need to include the multiply operator:
y=k*(x-x1)+y1;

Community Treasure Hunt

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

Start Hunting!

Translated by