# Introduction to some of the functions in SymPy


```python
import sympy as smp
from sympy import *
```


```python
x = smp.symbols('x')
```


```python
x**3
```




$\displaystyle x^{3}$




```python
x , y = smp.symbols('x y')
```


```python
f = x**2 + y **2 
```


```python
f.subs(x,10) # substituting the value of x
```




$\displaystyle y^{2} + 100$




```python
f.subs(y,3)  # substituting the value of y
```




$\displaystyle x^{2} + 9$




```python
smp.sin(x)
```




$\displaystyle \sin{\left(x \right)}$




```python
smp.exp(1/x) # exponent
```




$\displaystyle e^{\frac{1}{x}}$




```python
smp.log(x) #Natural log
```




$\displaystyle \log{\left(x \right)}$




```python
smp.log(x,10) # log with a base 10
```




$\displaystyle \frac{\log{\left(x \right)}}{\log{\left(10 \right)}}$




```python
x**(smp.Rational(7,2)) # keeping the power odf x in fraction
```




$\displaystyle x^{\frac{7}{2}}$



# Lets test our Fortune with Limits.


```python
smp.sin(x/2+smp.sin(x))
```




$\displaystyle \sin{\left(\frac{x}{2} + \sin{\left(x \right)} \right)}$




```python
smp.limit(smp.sin(x/2+smp.sin(x)),x,smp.pi)
```




$\displaystyle 1$




```python
2*smp.exp(1/x)/(smp.exp(1/x)+1)
```




$\displaystyle \frac{2 e^{\frac{1}{x}}}{e^{\frac{1}{x}} + 1}$




```python
smp.limit(2*smp.exp(1/x)/(smp.exp(1/x)+1),x,0,dir ='+')
```




$\displaystyle 2$




```python
smp.limit(2*smp.exp(1/x)/(smp.exp(1/x)+1),x,0,dir ='-')
```




$\displaystyle 0$




```python
(smp.cos(x)-1)/x
```




$\displaystyle \frac{\cos{\left(x \right)} - 1}{x}$




```python
smp.limit(((smp.cos(x)-1)/x),x,smp.oo)   # Here smp.oo defins a limit of x with indinity..
```




$\displaystyle 0$



# Derivatives.........


```python
((1 + smp.sin(x))/(1-smp.cos(x)))**2
```




$\displaystyle \frac{\left(\sin{\left(x \right)} + 1\right)^{2}}{\left(1 - \cos{\left(x \right)}\right)^{2}}$




```python
smp.diff(((1 + smp.sin(x))/(1-smp.cos(x)))**2,x)
```




$\displaystyle \frac{2 \left(\sin{\left(x \right)} + 1\right) \cos{\left(x \right)}}{\left(1 - \cos{\left(x \right)}\right)^{2}} - \frac{2 \left(\sin{\left(x \right)} + 1\right)^{2} \sin{\left(x \right)}}{\left(1 - \cos{\left(x \right)}\right)^{3}}$




```python
smp.log(x,5)**(x/2)
```




$\displaystyle \left(\frac{\log{\left(x \right)}}{\log{\left(5 \right)}}\right)^{\frac{x}{2}}$




```python
smp.diff(smp.log(x,5)**(x/2),x)
```




$\displaystyle \left(\frac{\log{\left(x \right)}}{\log{\left(5 \right)}}\right)^{\frac{x}{2}} \left(\frac{\log{\left(\frac{\log{\left(x \right)}}{\log{\left(5 \right)}} \right)}}{2} + \frac{1}{2 \log{\left(x \right)}}\right)$




```python
# Let's Start with an abstract approach........../////

f,g = smp.symbols('f g', cls = smp.Function)
g = g(x)
f = f(x+g)
```


```python
f
```




$\displaystyle f{\left(x + g{\left(x \right)} \right)}$




```python
smp.diff(f,x) #Derivative of f with respect to x
```




$\displaystyle \left(\frac{d}{d x} g{\left(x \right)} + 1\right) \left. \frac{d}{d \xi_{1}} f{\left(\xi_{1} \right)} \right|_{\substack{ \xi_{1}=x + g{\left(x \right)} }}$



# Intergration {Indefinate}


```python
smp.cos(x)*smp.cot(x)
```




$\displaystyle \cos{\left(x \right)} \cot{\left(x \right)}$




```python
smp.integrate(smp.cos(x)*smp.cot(x),x)  #By defalt SciPy do not give the conatant term. Hence, we have to keep this in mind 
```




$\displaystyle \frac{\log{\left(\cos{\left(x \right)} - 1 \right)}}{2} - \frac{\log{\left(\cos{\left(x \right)} + 1 \right)}}{2} + \cos{\left(x \right)}$




```python
smp.csc(x)  #Cosec is coined as csc
```




$\displaystyle \csc{\left(x \right)}$




```python
4*smp.sec(3*x)*smp.tan(3*x)
```




$\displaystyle 4 \tan{\left(3 x \right)} \sec{\left(3 x \right)}$




```python
smp.integrate(4*smp.sec(3*x)*smp.tan(3*x),x)
```




$\displaystyle \frac{4}{3 \cos{\left(3 x \right)}}$




```python
2/smp.sqrt(1-x**2) - 1/(x)**(smp.Rational(1,4))
```




$\displaystyle \frac{2}{\sqrt{1 - x^{2}}} - \frac{1}{\sqrt[4]{x}}$




```python
smp.integrate(2/smp.sqrt(1-x**2) - 1/(x)**(smp.Rational(1,4)),x)
```




$\displaystyle - \frac{4 x^{\frac{3}{4}}}{3} + 2 \operatorname{asin}{\left(x \right)}$



# Initial Value Function

#1 Given [dy/dx = 8x+csc^2(x)] with y(pi/2)= -7 solve for y(x)


```python
integral = 8*x + (smp.csc(x))**2  # in the give equation we Take Integral Both Sides.
```


```python
integral = smp.integrate((integral),x)  # now, we will try to calculate the constat term {C}.
```


```python
integral.subs(x,smp.pi/2)   # substuiting the value of x with pi/2 we get pi^2
```




$\displaystyle \pi^{2}$




```python
C = -integral.subs(x,smp.pi/2) - 7
y = integral + C
```


```python
y.subs(x,smp.pi/2) # Verification
```




$\displaystyle -7$




```python
y   # as function of x
```




$\displaystyle 4 x^{2} - \pi^{2} - 7 - \frac{\cos{\left(x \right)}}{\sin{\left(x \right)}}$



#2 let me just define it--


```python
(1+smp.sqrt(x))**(smp.Rational(1,3))  / x**(smp.Rational(1,2))
```




$\displaystyle \frac{\sqrt[3]{\sqrt{x} + 1}}{\sqrt{x}}$




```python
smp.integrate((1+smp.sqrt(x))**(smp.Rational(1,3))  / x**(smp.Rational(1,2)),x)
```




$\displaystyle \frac{3 \sqrt{x} \sqrt[3]{\sqrt{x} + 1}}{2} + \frac{3 \sqrt[3]{\sqrt{x} + 1}}{2}$



#3


```python
x*(1-x**2)**smp.Rational(1/4)
```




$\displaystyle x \sqrt[4]{1 - x^{2}}$




```python
smp.integrate(x*(1-x**2)**smp.Rational(1/4),x)
```




$\displaystyle \frac{2 x^{2} \sqrt[4]{1 - x^{2}}}{5} - \frac{2 \sqrt[4]{1 - x^{2}}}{5}$




```python
(2*x-1)*smp.cos((3*(2*x-1)**2+6)**smp.Rational(1/2)) /(3*(2*x-1)**2+6)**smp.Rational(1/2)

```




$\displaystyle \frac{\left(2 x - 1\right) \cos{\left(\sqrt{3 \left(2 x - 1\right)^{2} + 6} \right)}}{\sqrt{3 \left(2 x - 1\right)^{2} + 6}}$




```python
smp.integrate((2*x-1)*smp.cos((3*(2*x-1)**2+6)**smp.Rational(1/2)) /(3*(2*x-1)**2+6)**smp.Rational(1/2),x)
```




$\displaystyle \frac{\sin{\left(\sqrt{3 \left(2 x - 1\right)^{2} + 6} \right)}}{6}$



# Integration{Definate}


```python
smp.exp(x)/(smp.exp(2*x)+9)**smp.Rational(1,2)
```




$\displaystyle \frac{e^{x}}{\sqrt{e^{2 x} + 9}}$




```python
smp.integrate(smp.exp(x)/(smp.exp(2*x)+9)**(smp.Rational(1,2)),(x,0,smp.log(4)))  #asin(x) is inverse of sin(x)
```




$\displaystyle - \operatorname{asinh}{\left(\frac{1}{3} \right)} + \operatorname{asinh}{\left(\frac{4}{3} \right)}$




```python
x**10 * smp.exp(x)
```




$\displaystyle x^{10} e^{x}$




```python
t = smp.symbols('t')
```


```python
smp.integrate(x**10 * smp.exp(x),(x,1,t))
```




$\displaystyle \left(t^{10} - 10 t^{9} + 90 t^{8} - 720 t^{7} + 5040 t^{6} - 30240 t^{5} + 151200 t^{4} - 604800 t^{3} + 1814400 t^{2} - 3628800 t + 3628800\right) e^{t} - 1334961 e$



# Improper Integrals


```python
(16*smp.atan(x))/ (1+x**2)
```




$\displaystyle \frac{16 \operatorname{atan}{\left(x \right)}}{x^{2} + 1}$




```python
smp.integrate((16*smp.atan(x))/ (1+x**2),(x,0,smp.oo))   #Very Cool
```




$\displaystyle 2 \pi^{2}$



# Summation Functions


```python
n = smp.symbols('n')
```


```python
6/4**n
```




$\displaystyle 6 \cdot 4^{- n}$




```python
smp.Sum(6/4**n, (n,0,smp.oo))
```




$\displaystyle \sum_{n=0}^{\infty} 6 \cdot 4^{- n}$




```python
#Bro Solve it ///////

smp.Sum(6/4**n, (n,0,smp.oo)).doit()

#///// WE have TO TELL SCIPY TO doit()
```




$\displaystyle 8$




```python
smp.Sum(2**(n+1)/5**n, (n,0,smp.oo))
```




$\displaystyle \sum_{n=0}^{\infty} 2^{n + 1} \cdot 5^{- n}$




```python
smp.Sum(2**(n+1)/5**n, (n,0,smp.oo)).doit()
```




$\displaystyle \frac{10}{3}$




```python
smp.Sum(smp.atan(n)/n**smp.Rational(11,10), (n,1,smp.oo))
```




$\displaystyle \sum_{n=1}^{\infty} \frac{\operatorname{atan}{\left(n \right)}}{n^{\frac{11}{10}}}$




```python
smp.Sum(smp.atan(n)/n**smp.Rational(11,10), (n,1,smp.oo)).doit()  # Some time it does not work..
```




$\displaystyle \sum_{n=1}^{\infty} \frac{\operatorname{atan}{\left(n \right)}}{n^{\frac{11}{10}}}$




```python
#Lets try this!! {.n()}
smp.Sum(smp.atan(n)/n**(smp.Rational(11,10)), (n,1,smp.oo)).n()
#////////Here, we are actually dealing with approximations./////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
```




$\displaystyle 15.3028821020457$




```python
smp.Sum((1+smp.cos(n))/n**2, (n,1,smp.oo)).n()
```




$\displaystyle 1.969$




```python
# Happy Learning
```

991a207e09313687b6096800faa9ececf8f21131
ipynb
Jupyter Notebook
Calclus_BASICS.ipynb
DhruvKumarPHY/Mathematics_With_Python
90823f2385a2ef515d9172744a7168fa752d1cc8
MIT
Calclus_BASICS.ipynb
DhruvKumarPHY/Mathematics_With_Python
90823f2385a2ef515d9172744a7168fa752d1cc8
MIT
Calclus_BASICS.ipynb
DhruvKumarPHY/Mathematics_With_Python
90823f2385a2ef515d9172744a7168fa752d1cc8
MIT
Qwen/Qwen-72B
1. YES
2. YES