App SRM Unit 5 Notes
App SRM Unit 5 Notes
sym.limit(sym.sin(x) / x, x, 0)
-----1
sym.limit(x, x, sym.oo)
------oo
sym.limit(1 / x, x, sym.oo)
------0
sym.limit(x ** x, x, 0)
---------1
Differentiation
sym.diff(sym.sin(x), x)
-----cos(x)
sym.diff(sym.sin(2 * x), x)
-----2*cos(2*x)
sym.diff(sym.sin(2 * x), x, 1)
2*cos(2*x)
sym.diff(sym.sin(2 * x), x, 2)
-4*sin(2*x)
sym.diff(sym.sin(2 * x), x, 3)
-8*cos(2*x)
Series
sym.series(sym.cos(x), x)
2 4
x x / 6\
1 - -- + -- + O\x /
2 24
sym.series(1/sym.cos(x), x)
2 4
x 5*x / 6\
1 + -- + ---- + O\x /
2 24
Integration
>>>sym.integrate(6 * x ** 5, x)
6
x
>>> sym.integrate(sym.sin(x), x)
-cos(x)
>>> sym.integrate(sym.log(x), x)
x*log(x) - x
>>> sym.integrate(2 * x + sym.sinh(x), x)
2
x + cosh(x)
sym.integrate(x**3, (x, -1, 1))
0
>>> sym.integrate(sym.sin(x), (x, 0, sym.pi / 2))
1
>>> sym.integrate(sym.cos(x), (x, -sym.pi / 2, sym.pi / 2))
2
Equation solving
sym.solveset(x ** 4 - 1, x)
{-1, 1, -I, I}
sym.solveset(sym.exp(x) + 1, x)
{I*(2*n*pi + pi) | n in Integers}
solution = sym.solve((x + 5 * y - 2, -3 * x + 6 * y - 15), (x, y))
>>> solution[x], solution[y]
(-3,1)
sym.satisfiable(x & y)
{x: True, y: True}
sym.satisfiable(x & ~x)
False
Matrices
sym.Matrix([[1, 0], [0, 1]])
[1 0]
[0 1]
>>> x, y = sym.symbols('x, y')
>>> A = sym.Matrix([[1, x], [y, 1]])
>>> A
[1 x]
[ ]
[y 1]
>>> A**2
[x*y + 1 2*x ]
[ ]
[ 2*y x*y + 1]
Symbolic Maths in Python
from sympy import Symbol, symbols
X = Symbol('X')
expression = X + X + 1
print(expression)
a, b, c = symbols('a, b, c')
expression = a*b + b*a + a*c + c*a
print(expression)
o/p:2*X + 1
2*a*b + 2*a*c
Factorization And Expansion
• One important thing to note is, in NFA, if any path for an input string
leads to a final state, then the input string accepted. For example, in
above NFA, there are multiple paths for input string “00”. Since, one
of the paths leads to a final state, “00” is accepted by above NFA.
•
Problem-2: Construction of a minimal NFA accepting a set of strings
over {a, b} in which each string of the language is not containing ‘a’ as
the substring.
Explanation: The desired language will be like:
L1 = {b, bb, bbbb, ...........}Here as we can see that each string of the
above language is not containing ‘a’ as the substring But the below
language is not accepted by this NFA because some of the string of
below language is containing ‘a’ as the substring.
L2 = {ab, aba, ababaab..............}The state transition diagram of the
desired language will be like below:
def stateY(n):
#if length of n become 0
#then print accepted
if(len(n)==0):
print("string accepted")
else:
#if at zero index
#'a' found then
#print not accepted
if (n[0]=='a'):
print("String not accepted")
#take input
n=input()