```python
#from sympy import *
import sympy as sy
import numpy as np
import matplotlib.pyplot as plt

from IPython.display import display, Math

sy.init_printing()
```

The second command makes sure that formulas are presented in a graphical way, if
possible. Then, we generate a symbol and define the integrand:


```python
x = sy.symbols('x') #Python object of type Symbol
#f1 = sy.Lambda(x, (x**2)) # SymPy Lambda function
f1 = sy.lambdify(x, (x**2), "numpy")
#f2 = sy.Lambda(x, (4*x)) # SymPy Lambda function
f2 = sy.lambdify(x, (4*x), "numpy")
display(f1)
display(f2)
```


    <function _lambdifygenerated(x)>



    <function _lambdifygenerated(x)>



```python
p_range = (x,-1,5)
p = sy.plot(f1(x), f2(x), p_range, show=True)
```

Now we start with the symbolic computation of the integral:


```python
if1 = sy.Lambda(x, sy.integrate(f1(x),x))
if2 = sy.Lambda(x, sy.integrate(f2(x),x))
display(if1)
display(if2)
```

## Poiščemo presečišče krivulj


```python
presecisca = sy.solve(f1(x) - f2(x), x)
print(f'najdena presecisca so {presecisca}')
```

    najdena presecisca so [0, 4]


## narišemo iskane pološčine


```python
#x = symbols('x')
#f = sin(x)

x_array = np.linspace(0, 4, 10)
f1_array = f1(x_array)
f2_array = f2(x_array)


print(x_array)
print(f1_array)
#f_array = sy.lambdify(x, f)(x_array)

fig, ax = plt.subplots()

ax.plot(x_array, f1_array, color = 'r', label='f1')
ax.plot(x_array, f2_array, color = 'b', label='f2')

ax.fill_between(x_array, f1_array, f2_array, facecolor = 'grey', alpha = 0.5)

ax.legend()
plt.show()
```

## Izračunamo ploščino med krivuljama s uporabo določenega integrala

surface = definite integral in range x -> 0, 4


```python
s1 = if1(4) - if1(0)
s2 = if2(4) - if2(0)

print(f'ploščina med abciso in krivuljo je {s1}, med abciso in premico pa {s2}')

# ker je premica nad krivuljo, ima večjo površino in odštevamo od nje
s = s2 - s1
print(f'ploščina med krivuljama med x=0 in x=4 je {s}')
```

    ploščina med abciso in krivuljo je 64/3, med abciso in premico pa 32
    ploščina med krivuljama med x=0 in x=4 je 32/3



```python

```

3440fa5b283e493fd279b4c1f1daa067da7e183d
ipynb
Jupyter Notebook
theory/sympy/sympy-integriranje.ipynb
CrtomirJuren/python-delavnica
db96470d2cb1870390545cfbe511552a9ef08720
MIT
theory/sympy/sympy-integriranje.ipynb
CrtomirJuren/python-delavnica
db96470d2cb1870390545cfbe511552a9ef08720
MIT
theory/sympy/sympy-integriranje.ipynb
CrtomirJuren/python-delavnica
db96470d2cb1870390545cfbe511552a9ef08720
MIT
Qwen/Qwen-72B
1. YES
2. YES