MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Asked by Sarah on 29 Oct 2011

Howdy, I need help with this matlab related problem.

I have the equation of a curve and I need to find the tangent line at a given point. What should I be typing to make this happen?

I figured out how to get the derivative of the curve, but I have no idea how to make matlab run the x value of the given point to give me the slope (m) of the tangent line and plug that into the equation y-y_1=m(x-x_1).

I also need to plot the tangent line with the original curve. Do I just use plot(x,y)? Please help me, I have no idea how to type programming properly.

I also need to make the given point show up as an open circle on the graph. How do I do this?

**update**

It is a homework question, but I wanted to be a bit vague so I could get guided into solving it on my own, but after spending two hours on it, I'm not getting anywhere closer to solving it.

The curve is a witch of Agnesi curve and the point is directly on it.

The open circle is for the graph, it wants the point of tangency to show as an open circle.

If anyone can give me step by step instructions on how to do it, I'd be wonderfully happy, unfortunately, I don't understand any computer language, so if you can explain in words too, that would be great.

**Update 2**

The curve and its derivative need to be graphed on the same graph.

*No products are associated with this question.*

Answer by Fangjun Jiang on 30 Oct 2011

Something like this:

%% delta_t=2*pi/100; t=0:delta_t:2*pi; y=sin(t); figure(1);grid on; plot(t,y,'r*');hold on; dt=gradient(t)/delta_t; dy=gradient(y)/delta_t; quiver(t,y,dt,dy); grid on;

## 4 Comments

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/19784#comment_43445

Do you know the relation between the derivative and the "m" in the line equation? Using this you can calculate the coordinates of 2 points on the tangent through (x,y): One before and one behind. Use PLOT to draw a connection through these points.

What does this mean: "make a given point show up as open circle"?

Please note, that you will not get much help in this forum without showing the code you ahve created already, especially if the problem sounds like a homework question.

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/19784#comment_43493

check above for my commentary to your comment

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/19784#comment_43505

do you need to create something like the 2nd figure on wikipedia?

http://en.wikipedia.org/wiki/Witch_of_Agnesi

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/19784#comment_43506

honestly, I'm not sure, I have to graph the curve and then its derivative on the same graph. I honestly have no idea what that will end up looking like.