Learn Python in Malayalam | Chapter 14 | How to solve differentiation in python

 


This is the 14th video on Learn python in Malayalam. This video clearly explains below topics,

use the below time link to skip to the specific topics


Topics covered in this video

Chapter 13 assignment discussion - 00:31

differentiation in python - 01:16

power rule  - 01:31

product rule - 03:36

multi-variable function - 05:10

first order differential equation response - 07:19

chapter 14 assignment - 11:09

 


Program used 

# Progra for power & product rule

import sympy as sym

x = sym.Symbol('x')

f = x**5+3*x

# f = ((x**2)+1)*sym.cos(x)

f_prime = sym.diff(f)

print(f_prime)


# program for multi variable function

import sympy as sym

x,y = sym.symbols('x y')

f = (x**4)*y

f_prime = sym.diff(f,y)

print(f_prime)


#program fro first order differential equation

import numpy as np

from scipy.integrate import odeint

import matplotlib.pyplot as plt

 

# function that returns dx/dt

def model(x,t):

    k = .5

    dxdt = -k * x

    return dxdt

 

# initial condition

x0 = 5

 

# time points

t = np.linspace(0,20)

 

# solve ODE

x = odeint(model,x0,t)

 

# plot results

plt.plot(t,x,label="K=0.5")

plt.title("First order Differential equation response")

plt.xlabel('time')

plt.ylabel('x')

plt.legend()

plt.show()


For more check out here : https://iammanuprasad.blogspot.com/



Learn Python in Malayalam Playlist: 

https://www.youtube.com/playlist?list=PLmKq-kgKY8uZya3cwcX6otT61NPHXbTK0


Chapter 1 -  https://youtu.be/WiyQ8wTsRO0

Introduction to programming

Introduction to Python

Introduction to Google Co-lab

How to setup Google Co-lab


Chapter 2 -  https://youtu.be/YFngtW42Mls

Python Identifiers

Lines and Indentation

Multi-Line Statements


Chapter 3 - https://youtu.be/gxalG8Aps0A

Quotation in python

Comments in python

Assigning values to variable


Chapter 4 - https://youtu.be/AaEL_f2RHIk

Data types

Numbers

Strings


Chapter 5 - https://youtu.be/irND35-6BZ0

Data types

Lists

Tuple

Dictionary


Chapter 6 - https://youtu.be/MRfg2QZBHvE

Decision making

if condition

if .. else condition

Nested if


Chapter 7 - https://youtu.be/VYXndepcTCM

Loops in Python

while loop

for loop

nested loop


Chapter 8 - https://youtu.be/d7Y2D9H4u7c

Functions in python

arguments in function

Multiple arguments in function

Arbitrary arguments in function

Return value in function


Chapter 9 - https://youtu.be/hFOTKyYCkdw 

Classes in python

Defining a class

Creating an object

Constructors in python


Chapter 10 - https://youtu.be/w-_x2vfpJk0

Matrix in python

Defining matrix in python

Matrix addition

Matrix multiplication

Transpose of a matrix

Inverse of matrix

Rank & eigen values of matrix


Chapter 11 - https://youtu.be/-7DB7OEenms

Plotting in Python

  Line Plot

  Stem Plot

  Bar Plot

  Scatter Plot

  Box Plot

  Histogram

  Multiple Plot, Subplot, plot within plot


Chapter 12 - https://youtu.be/aID_Dlx-oys 

File handling in python

  Generate file data 

  Save the data in a variable

  write data to a csv file

  read from the csv file

  plotting the data from the scv file

  standard deviation & mean of data

  location of the saved file 


Chapter 13 - https://youtu.be/zk6Fcs-NY6I

  System linear equation solution

  Example with explanation

  Program for solving linear equation


If you like my video please subscribe my channel and share


Important links & key words


https://www.python.org/

Google COLAB


Music: https://www.bensound.com

Reff : https://www.tutorialspoint.com/python/python_variable_types.htm 

https://www.w3schools.com/

https://towardsdatascience.com/taking-derivatives-in-python-d6229ba72c64


Learn Python in Malayalam | Chapter 13 | Solving linear equation using matrix method in Python

 


This is the 13th video on Learn python in Malayalam. This video clearly explains below topics, use the below time link to skip to the specific topics Topics covered in this video System linear equation solution - 0:28 Example with explanation - 01:00 Program for solving linear equation - 03:30 Chapter 13 assignment - 07:33 Program used # program for assigning matrix values, inverse of matrix and displaying # importing libraries from scipy import * from pylab import * from numpy import * A=array([[3,2,-5],[1,-3,2],[5,-1,4]])# assigning the values to matrix A from the equaton b = array([12,-13,10]) # assigning the values of b matrix print("A matrix is") print(A) # printing the A matrix print("b matrix is") print(b) #printing then b matrix X=inv(A).dot(b) # calculating the values of x,y,z print("X matrix is") print(X) # printing the X matrix # printing each values print("the value of x is :",round(X[0],2)) print("the value of y is :",round(X[1],2)) print("the value of z is :",round(X[2],2)) For more check out here : https://iammanuprasad.blogspot.com/ https://iammanuprasad.blogspot.com/2020/10/experiment-no-3-realization-of-arrays.html Learn Python in Malayalam Playlist: https://www.youtube.com/playlist?list=PLmKq-kgKY8uZya3cwcX6otT61NPHXbTK0 Chapter 1 - https://youtu.be/WiyQ8wTsRO0 Introduction to programming Introduction to Python Introduction to Google Co-lab How to setup Google Co-lab Chapter 2 - https://youtu.be/YFngtW42Mls Python Identifiers Lines and Indentation Multi-Line Statements Chapter 3 - https://youtu.be/gxalG8Aps0A Quotation in python Comments in python Assigning values to variable Chapter 4 - https://youtu.be/AaEL_f2RHIk Data types Numbers Strings Chapter 5 - https://youtu.be/irND35-6BZ0 Data types Lists Tuple Dictionary Chapter 6 - https://youtu.be/MRfg2QZBHvE Decision making if condition if .. else condition Nested if Chapter 7 - https://youtu.be/VYXndepcTCM Loops in Python while loop for loop nested loop Chapter 8 - https://youtu.be/d7Y2D9H4u7c Functions in python arguments in function Multiple arguments in function Arbitrary arguments in function Return value in function Chapter 9 - https://youtu.be/hFOTKyYCkdw Classes in python Defining a class Creating an object Constructors in python Chapter 10 - https://youtu.be/w-_x2vfpJk0 Matrix in python Defining matrix in python Matrix addition Matrix multiplication Transpose of a matrix Inverse of matrix Rank & eigen values of matrix Chapter 11 - https://youtu.be/-7DB7OEenms Plotting in Python Line Plot Stem Plot Bar Plot Scatter Plot Box Plot Histogram Multiple Plot, Subplot, plot within plot Chapter 12 - https://youtu.be/aID_Dlx-oys File handling in python Generate file data Save the data in a variable write data to a csv file read from the csv file plotting the data from the scv file standard deviation & mean of data location of the saved file If you like my video please subscribe my channel and share Important links & key words https://www.python.org/ Google COLAB Music: https://www.bensound.com Reff : https://www.tutorialspoint.com/python/python_variable_types.htm https://www.w3schools.com/

Learn Python in Malayalam|Chapter 12|File handling in Python | Read & write a file






This is the 12th video on Learn python in Malayalam. This video clearly explains below topics,
use the below time link to skip to the specific topics

Topics covered in this video
Chapter 11 Assignment discussion -  00:48
File handling in python - 03:48
Generate file data - 04:38  
Save the data in a variable - 05:41
write data to a csv file - 06:18
read from the csv file - 08:46
plotting the data from the scv file - 09:52
standard deviation & mean of data - 11:09
location of the saved file - 11:57


Program used 

#importing libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Get x values of the wave
t = np.linspace(0,1,100)
# calculating the amplitude
y = np.sin(2*np.pi*t) # calculating sine wave
dat = [t,y]
# writing the value in to data.csv
df = pd.DataFrame(data=dat,index=["Time","Amplitude"]).T
# df
df.to_csv('data.csv')
#Reading the file data.csv
df1=pd.read_csv('data.csv',index_col=0)
# df1
#Plotting the function from read value
df1.plot(x="Time",y="Amplitude")
plt.show()
 
# Creating histogram 
df1.hist(column="Amplitude")
# Show plot 
plt.show() 
# Standard deviation of the value
print("Standard Deviation")
print(df1.std(0))
# Mean of the values
print("Mean")
print(df1.mean(0))

Assignment Solution
from numpy import *
from matplotlib.pyplot import *
# Get x values of the sine wave
t = arange(0, 10, 0.01);
# calculating the amplitude
y1 = cos(t)
y2 = cos(5*t)
y = y1*y2+y2
# plotting cos signals in subplot
rcParams["figure.figsize"] = (10,10) # changing the figure size 
fig, axs = subplots(3)
axs[0].plot(t,y1) 
axs[0].set_title("cos(t) signal ")
axs[1].plot(t,y2)
axs[1].set_title("cos(5*t) Signal")
axs[2].plot(t,y)  
axs[2].set_title("cos(t)*cos(5*t)+cos(5*t)")
show() # showing the figure

For more check out here : https://iammanuprasad.blogspot.com/

Learn Python in Malayalam Playlist: 
https://www.youtube.com/playlist?list=PLmKq-kgKY8uZya3cwcX6otT61NPHXbTK0

Chapter 1 -  https://youtu.be/WiyQ8wTsRO0
Introduction to programming
Introduction to Python
Introduction to Google Co-lab
How to setup Google Co-lab

Chapter 2 -  https://youtu.be/YFngtW42Mls
Python Identifiers
Lines and Indentation
Multi-Line Statements

Chapter 3 - https://youtu.be/gxalG8Aps0A
Quotation in python
Comments in python
Assigning values to variable

Chapter 4 - https://youtu.be/AaEL_f2RHIk
Data types
Numbers
Strings

Chapter 5 - https://youtu.be/irND35-6BZ0
Data types
Lists
Tuple
Dictionary

Chapter 6 - https://youtu.be/MRfg2QZBHvE
Decision making
if condition
if .. else condition
Nested if

Chapter 7 - https://youtu.be/VYXndepcTCM
Loops in Python
while loop
for loop
nested loop

Chapter 8 - https://youtu.be/d7Y2D9H4u7c
Functions in python
arguments in function
Multiple arguments in function
Arbitrary arguments in function
Return value in function

Chapter 9 - https://youtu.be/hFOTKyYCkdw 
Classes in python
Defining a class
Creating an object
Constructors in python

Chapter 10 - https://youtu.be/w-_x2vfpJk0
Matrix in python
Defining matrix in python
Matrix addition
Matrix multiplication
Transpose of a matrix
Inverse of matrix
Rank & eigen values of matrix

Chapter 11 - https://youtu.be/-7DB7OEenms
Plotting in Python
  Line Plot
  Stem Plot
  Bar Plot
  Scatter Plot
  Box Plot
  Histogram
  Multiple Plot, Subplot, plot within plot

If you like my video please subscribe my channel and share

Important links & key words

https://www.python.org/
Google COLAB

Music: https://www.bensound.com
Reff : https://www.tutorialspoint.com/python/python_variable_types.htm 
https://www.w3schools.com/

Learn Python in Malayalam|Chapter 11 | Plotting & Visualization in python | Subplot | Bar Plot |

 


This is the eleventh video on Learn python in Malayalam. This video clearly explains below topics, use the below time link to skip to the specific topics Topics covered in this video 1. Chapter 10 discussion - 00:35 2. Plotting in Python - 02:05 3. Line Plot - 02:23 4. Stem Plot - 06:12 5. Bar Plot - 06:49 6. Scatter Plot - 08:03 7. Box Plot - 09:21 8. Histogram - 11:23 9. Multiple Plot, Subplot, plot within plot - 13:39 10.Chapter 11 Assignment - 17:41 Learn Python in Malayalam Playlist: https://www.youtube.com/playlist?list=PLmKq-kgKY8uZya3cwcX6otT61NPHXbTK0 Chapter 1 - https://youtu.be/WiyQ8wTsRO0 Introduction to programming Introduction to Python Introduction to Google Co-lab How to setup Google Co-lab Chapter 2 - https://youtu.be/YFngtW42Mls Python Identifiers Lines and Indentation Multi-Line Statements Chapter 3 - https://youtu.be/gxalG8Aps0A Quotation in python Comments in python Assigning values to variable Chapter 4 - https://youtu.be/AaEL_f2RHIk Data types Numbers Strings Chapter 5 - https://youtu.be/irND35-6BZ0 Data types Lists Tuple Dictionary Chapter 6 - https://youtu.be/MRfg2QZBHvE Decision making if condition if .. else condition Nested if Chapter 7 - https://youtu.be/VYXndepcTCM Loops in Python while loop for loop nested loop Chapter 8 - https://youtu.be/d7Y2D9H4u7c Functions in python arguments in function Multiple arguments in function Arbitrary arguments in function Return value in function Chapter 9 - https://youtu.be/hFOTKyYCkdw Classes in python Defining a class Creating an object Constructors in python Chapter 10 - https://youtu.be/w-_x2vfpJk0 Matrix in python Defining matrix in python Matrix addition Matrix multiplication Transpose of a matrix Inverse of matrix Rank & eigen values of matrix If you like my video please subscribe my channel and share Important links & key words https://www.python.org/ Google COLAB Music: https://www.bensound.com Reff : https://www.tutorialspoint.com/python/python_variable_types.htm https://www.w3schools.com/

Experiment No 8 : Coin Toss and the Level Crossing Problem

Objective

  • Simulate a coin toss that maps a head as 1 and tail as 0.

  • Toss the coin N = 100, 500, 1000, 5000 and 500000 times and compute the probability (p) of head in each case.

  • Compute the absolute error | 0:5 - p | in each case and plot against N and understand the law of large numbers.

  • Create a uniform random vector with maximum magnitude 10, plot and observe.

  • Set a threshold (VT = 2) and count how many times the random function has crossed VT .

  • Count how many times the function has gone above and below the threshold.


Theory

The action of tossing a coin has two possible outcomes: Head or Tail. You don’t know which outcome you will obtain on a particular toss, but you do know that it will be either Head or Tail (we rule out the possibility of the coin landing on its edge!). Contrast this with a science experiment. For example, if your experiment is to drop an object, you know the outcome for sure: the object will fall towards the ground. However, tossing a coin is a random experiment, as you do know the set of outcomes, but you do not know the exact outcome for a particular execution of the random experiment.

When we flip a coin there is always a probability to get a head or a tail is 50 percent.

Suppose a coin tossed then we get two possible outcomes either a ‘head’ (H) or a ‘tail’ (T), and it is impossible to predict whether the result of a toss will be a ‘head’ or ‘tail’.


The probability for equally likely outcomes in an event is: 

Number of favourable outcomes ÷ Total number of possible outcomes

Total number of possible outcomes = 2


(i) If the favourable outcome is head (H).

Number of favourable outcomes = 1.

Therefore, P(getting a head)

P(H) =Number of favorable outcomestotal number of possible outcomes

= 1/2.

(ii) If the favourable outcome is tail (T).

Number of favourable outcomes = 1.

Therefore, P(getting a tail)

P(H) =Number of favorable outcomestotal number of possible outcomes

= 1/2.

Program  for coin toss

import random

def coinToss(number):

    recordList= [] # multiple assignment

    for i in range(number): # do this 'number' amount of times

         flip = random.randint(0, 1)

         if (flip == 0):

              # print("Heads")

              recordList.append(1)

         else:

              # print("Tails")

              recordList.append(0)

    print("Coin Toss result is :",str(recordList))

    print("No of Heads :",recordList.count(1), "No of Tails :",recordList.count(0))

 

coinToss(10)

Output

Coin Toss result is : [1, 0, 0, 0, 0, 1, 1, 0, 0, 1]

No of Heads : 4 No of Tails : 6


Program for N vs absolute error

import random

import matplotlib.pyplot as plt

N = [10, 100, 500,1000,5000,10000,50000]

ab_errList = []

for j in N:

  recordList= [] 

  

  for i in range(j): # do this 'number' amount of times

      flip = random.randint(0, 1)

      if (flip == 0):

            # print("Heads")

            recordList.append(1)

      else:

            # print("Tails")

            recordList.append(0)

# print("Coin Toss result is :",str(recordList))

  print("Value of N is :",j)

  print("No of Heads :",recordList.count(1), "No of Tails :",recordList.count(0))

  Prob_H = (recordList.count(1))/j

  Prob_T = (recordList.count(0))/j

  print("Probability of Head is :",Prob_H)

  print("Probability of Tail is :",Prob_T)

  ab_err = 0.5 - Prob_H

  print("Absolute error :",round(ab_err,3))

  print("")

  ab_errList.append(round(ab_err,3))

 

print(ab_errList)

plt.plot(N,ab_errList)

plt.title("N vs Absolute error")

plt.xlabel("N")

plt.ylabel("Absolute error")

plt.show()

 

Output

Value of N is : 100

No of Heads : 56 No of Tails : 44

Probability of Head is : 0.56

Probability of Tail is : 0.44

Absolute error : -0.06


Value of N is : 500

No of Heads : 250 No of Tails : 250

Probability of Head is : 0.5

Probability of Tail is : 0.5

Absolute error : 0.0


Value of N is : 1000

No of Heads : 497 No of Tails : 503

Probability of Head is : 0.497

Probability of Tail is : 0.503

Absolute error : 0.003


Value of N is : 5000

No of Heads : 2529 No of Tails : 2471

Probability of Head is : 0.5058

Probability of Tail is : 0.4942

Absolute error : -0.006


Value of N is : 50000

No of Heads : 25041 No of Tails : 24959

Probability of Head is : 0.50082

Probability of Tail is : 0.49918

Absolute error : -0.001


[-0.06, 0.0, 0.003, -0.006, -0.001]


Program for threshold value

# importing the library files

import numpy as np

import matplotlib.pyplot as plt

#creating 50 uniform random vector with maximum value 10

s = np.random.uniform(0,10,50)

print(s) # printing the generated random values

plt.plot(s) # plotting the values

vt = 2 # setting threshold values

vt_p=np.full(s.shape,vt) # creating a threshold value vector

plt.plot(vt_p) # plotting the threshold value

# counting the values greater than threshold value

g_th = np.count_nonzero(s >= vt) 

print(" Number of values crossed threshold values : ",g_th) # printing the count

# counting the values less than threshold value

l_th = np.count_nonzero(s < vt)

print(" Number of values under threshold values : ",l_th)

plt.show() # showing the plot

Output

[8.59601571 2.1675848  1.31812203 6.70697231 7.19163019 9.52270116

 6.71189414 9.27098889 8.32502068 3.73868206 0.89465273 0.21778838

 4.08227646 4.68405434 7.55652276 5.01307735 3.58359511 4.07557471

 8.20357085 1.00133828 3.24105448 6.97113761 1.53276455 0.43369831

 9.45985372 7.63847741 7.79364829 7.92720212 8.29402836 9.85319232

 2.19810726 3.9236389  2.75348292 6.6756277  6.46252142 1.00647122

 4.40360799 3.30109673 6.29580294 0.15285471 2.31633687 1.37331892

 4.64744879 4.3281915  8.02196388 3.28039791 2.55710401 0.83424787

 4.09506397 1.13120688]

 Number of values crossed threshold values :  39

 Number of values under threshold values :  11


Inference

  • Simulated  coin toss that maps a head as 1 and tail as 0.

  • Tossed the coin N = 100, 500, 1000, 5000 and 500000 times and computed the probability (p) of head in each case.

  • Computed the absolute error | 0:5 - p | in each case and plot against N and understood the law of large numbers.

  • Created a uniform random vector with maximum magnitude 10, plotted and observed.

  • Threshold set as  (VT = 2) and counted how many times the random function has crossed VT .

  • Counted how many times the function has gone above and below the threshold.

Signals & System Lect 15 | Stable & Unstable Systems | Solved examples

  ECT 204 SIGNALS AND SYSTEMS Topics covered  00:00 - Introduction to Stable & unstable Systems 01:08 - BIBO criteria 03:38 Problem No 1...