Got Questions? Get Answers.
Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Ploting a tangent on a curve

Subject: Ploting a tangent on a curve

From: Neeta

Date: 19 Apr, 2011 21:36:05

Message: 1 of 2

Do you think a plot editor or curve fitting tool provides an option to plot a tangent on a data point of a curve. If not, what is the plot instruction that can be used on command window?

Subject: Ploting a tangent on a curve

From: Nasser M. Abbasi

Date: 19 Apr, 2011 22:22:34

Message: 2 of 2

On 4/19/2011 2:36 PM, Neeta wrote:
> Do you think a plot editor or curve fitting tool provides an option
> to plot a tangent on a data point of a curve. If not, what is
> the plot instruction that can be used on command window?

There is probably 101 ways to do this. There might
be allready one command to do it in Matlab.

But here is a hack. If you want to do it symbolically,
then just find the slope, and find equation of the line at
the point, and plot the tangent.

Here is an example for plotting tangent of sin(t) at
some point just for illustration.

---------------------------------
clear all; close all;
syms t
x2 = pi/5; %point to plot tangent
f = sin(t); %function to take slope of
m = subs(diff(f,t),t,x2); %find slope at x2
y2 = subs(f,t,x2);

intercept = -m*x2+y2;

ezplot(f,[0,2*pi]); % plot f(t)
hold on;
ezplot(m*t+intercept,[0,2*pi]); %plot tangent
h = get(gca,'children');
set(h(1),'color','red');

title(sprintf('tangent of sin(t) at x=%f',x2));
plot(x2,y2,'*');

ylim([-2 2])

-----------------------------

You could do it numerically also if you want.

HTH,

--Nasser

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us