Message Boards Message Boards

0
|
7774 Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Why Manipulate command is not working when ploting the tangent line?

Posted 11 years ago
Hi all,

I'm trying to get an interactive output that allows me to plot both the function f and its tangent line y by changing the parameter x0. However I'm not able to obtain the plot of y. This is the code:
f[x_] = x^2;
y[x_] = f[x0] + f'[x0]*(x - x0);
Manipulate[Plot[{y[x], f[x]}, {x, -4, 10}], {x0, 0, 6}] 


And this what I get:




As you see no tangent line appears.

Thanks a lot!
POSTED BY: Sergio Garcia
5 Replies
Posted 11 years ago
Thanks, Bruce!
POSTED BY: Sergio Garcia
Notes on typing posts, including keeping code looking good, are in

http://community.wolfram.com/groups/-/m/t/151347

I put your code into MCode boxes and the function arguments reappeared.
POSTED BY: Bruce Miller
Posted 11 years ago
Thanks a lot Michael now it works!

I did write the missing arguments of y and f in Mathematica but for some reason they dissapeared when copying them here.
POSTED BY: Sergio Garcia
Your original posted code does not work as in the illustration.  The function  f  and  y  are missing their arguments.

The reason it wouldn't work with  f  and  y  is that  Manipulate  localizes  x0.  This means the  x0  symbol in the definition of  y  is a different symbol than the  x0  in  Manipulate.

Here's a way to get what seems intended:
f[x_] = x^2;
y[x_, x0_] = f[x0] + f'[x0]*(x - x0);
Manipulate[Plot[{y[x, x0], f[x]}, {x, -4, 10}], {x0, 0, 6}]
POSTED BY: Michael Rogers
Posted 11 years ago
I found that if I write the whole expression of the tangent line inside the Manipulate command it works:
f[x_] = x^2;
Manipulate[Plot[{f[x0] + f'[x0]*(x - x0), f[x]}, {x, -4, 10}], {x0, 0, 6}]
Why is that?

Thanks!
POSTED BY: Sergio Garcia
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract