Calculus

http://d2l.ai/chapter_preliminaries/calculus.html

x = np.arange(0, 3, 0.1)
plot(x, [x ** 3 - 1 / x, 4 * x - 4], 'x', 'f(x)', legend=['f(x) = x ** 3 - 1 / x ', 'Tangent line (x=1) : y = 4 * x - 4 '])

2-4-e1

According to the power rule and multiple rule," 3 * x ** 2 + 1 / (x ** 2) "is the derivative function of f (x).

So x == 1,f’(1) ==3 * 1 **2 + 1 / (1 ** 2) == 3 + 1 == 4,tangent line’s slope is 4.

And we know, the tangent line passes the plot (1, 0).

So the function of the line is " y == 4 * (x - 1) == 4 * x -4"


I have some problem with saving the “plot” picture, so I just screenshoted it. :sweat_smile:

I can still remember it is easy to save other “plot” pictures (eg. Statsmodel)by double-clicking the pic and clicking the “save” botton in VScode.

Is there a way to save instead of screenshoting ? :expressionless:

Hi @StevenJokes! Here is a hint you can try!
https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.savefig.html

Is there a way to open it in VScode?
Or how to make it openable in VScode?
:sweat_smile:
The doc is not friendly to other users. :joy:
https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.savefig.html

Hi,

Thanks for the great content guys :slight_smile:
but i feel like giving examples in gradients and chain rule would be really helpful
Thanks

Hi @anandsm7, the gradients and chain rule are in section http://d2l.ai/chapter_appendix-mathematics-for-deep-learning/multivariable-calculus.html#multivariate-chain-rule. Feel free to do a search in the top right of our wensite as here:

1 Like

some apis:

  1. plt.gca

Get the current Axes instance on the current figure matching the given keyword args, or create one.

Examples:

To get the current polar axes on the current figure:

plt.gca(projection='polar')

If the current axes doesn’t exist, or isn’t a polar one, the appropriate axes will be created and then returned.


https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.gca.html


  1. axes.cla()

‘’’
Clear an axes, i.e. the currently active axes in the current figure. It leaves the other axes untouched.
‘’’


https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.cla.


  1. fmts:
  • ‘-’:solid line style 实线;
  • ‘m–’:magenta dashed line style 紫红色虚线;
  • ‘g-’:green dash-dotted line style 绿色点划线;
  • 'r:'red dotted line style 红色点线

For more:

  1. https://blog.csdn.net/leaf_zizi/article/details/87094168
  2. https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.plot.html#matplotlib.axes.Axes.plot
  3. https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_linestyle