```
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 '])
```

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.

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 ?

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?

The doc is not friendly to other users.

https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.savefig.html

Hi,

Thanks for the great content guys

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:

some apis:

- 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

- 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.

- fmts:

- โ-โ:solid line style ๅฎ็บฟ;
- โmโโ:magenta dashed line style ็ดซ็บข่ฒ่็บฟ;
- โg-โ:green dash-dotted line style ็ปฟ่ฒ็นๅ็บฟ๏ผ
- 'r:'red dotted line style ็บข่ฒ็น็บฟ

For more:

For the 2nd question in Excercises. Do we have different variables x1 and x2 or is it a single variable x ? If itโs a single variable, is it 5ex^2 that is in the equation?

Hi does D2L provide a way where we can validate or check our solutions for the exercises ?

Discussion is the only way now.

@rammy_vadlmudi

Hey @rammy_vadlamudi, yes! This discussion forum is great way to share your thoughts and discuss the solutions. Feel free to voice it out!

Hey guys hope u all good. Iโve found today this course. Itโs quite interesting. Iโm completing it in python. Iโm learning mostly python for machine learning and AI applications. Even iโve been learning how to manage to use AWS sagemaker and clouds services. But i wanted to ask a question about finding the gradient of the function. I mean question 2: Itโs possible to define

a function like

import numpy as np

def(x): where x is a list

return 3*x[0]**2 + 5*np.exp(x[1])

and then apply numerical_limit function with following parameters(f = f(x), x =[1,1], h =0.01)

and return a list looping thought each index of the list x =[1,1]

or this logic is too dump?

If you guys can help me

I studied math in the past, but donโt know how to code with the most fresh and efficient way x)

thanks in advance

Hi @Luis_Ramirez, your logic is never dump! In most of DL framework, we decompose a complex function to each directly *differentiable* step and then apply the chain rule (i,e., we define all the derivative formula in code and apply chain rule). Check https://d2l.ai/chapter_preliminaries/autograd.html for more details. Besides, if you would like to see how to code from scratch, check here. Let me know if it helps!

Try adding this line to the top of the plot function:

```
fig = d2l.plt.figure()
```

and have the plot function

```
return fig
```

then:

```
def f(x)
return(x**3-1/x)
x = np.arange(0.1, 3, 0.1)
fig = plot(x, [f(x), 4 * x-4], 'x', 'f(x)', legend=['f(x)', 'Tangent line (x=1)'])
```

```
fig.savefig("2_Prelim 4_Calc 1_Ex.jpg")
```

- Q1

hello,

I tried my code:

import torch

x = torch.arange(2.0)

x.requires_grad_(True)

x.grad

y = 3 * torch.dot(x,x) + 5 * torch.exp(x)

y

y.backward()

x.grad

ยฟitโs ok?

Hi, Iโm looking for some clarification on this excerpt from the very end of Section 2.4.3:

Similarly, for any matrix ๐, we have โ๐ โ๐โ_F^2 = 2๐.

Does this mean that for a given matrix of any size filled with m*n variables, the gradient of the square of that matrix can be condensed to 2X?

Also, what does the subscripted F imply in this case?

Thanks!

Hi, I just wanted to verify my solutions for the provided exercise questions:

- Find the gradient of the function ๐(๐ฑ)=3*(๐ฅ1 ^ 2) + 5๐^๐ฅ2

(Subsituting y for x2, as I assumed x1 != x2)

fโ(x) = 6x + 5e^y

- What is the gradient of the function ๐(๐ฑ)=โ๐ฑโ2

||x||2 = [ (3x^2)^2 + (5e^y)^2 ]^0.5

(Calculating the Euclidean distance using the Pythagorean Theorem)

||x|| = ( 9x^4 + 25e^2y ) ^ 0.5

fโ ( ||x|| ) = ( 18x^3 + 25e^2y ) / ( 9x^4 + 25e^2y ) ^ 0.5

- Can you write out the chain rule for the case where ๐ข=๐(๐ฅ,๐ฆ,๐ง), ๐ฅ=๐ฅ(๐,๐), ๐ฆ=๐ฆ(๐,๐), and ๐ง=๐ง(๐,๐)?

Is this meant to be simplified to df/dx * (dx/da + dx/db) and so on for y, and z?

Thanks so much, and I apologise if my answers are completely misguided.