forked from Manish57-droid/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbolic_programming.py
133 lines (92 loc) · 2.48 KB
/
symbolic_programming.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
"""Symbolic_Programming.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1PDqLP9WtTffRMi1ZMAAU3WEa5Qr5zFgN
"""
# Program 1 :
import sympy
from sympy import *
print(N(sqrt(2),100))
# Program 2 :
from sympy import *
a = Rational(1,2)
b = Rational(1,3)
print(a+b)
# Program 3 :
import sympy as sym
x = sym.Symbol('x')
y = sym.Symbol('y')
sym.expand((x+y)**6)
# Program 4 :
import sympy
from sympy import *
x =Symbol('x')
simplify(sin(x)/cos(x))
# Program 5 :
import sympy
from sympy import *
x =Symbol('x')
solveset((sin(x)-x)/(x**3),x)
# Program 6 :
import sympy
from sympy import *
x = symbols('x')
expr1 = log(x)
# Use sympy.Derivative() method
expr1_diff = Derivative(expr, x)
print("Derivative of expression with respect to x : {}".format(expr1_diff))
print("Value of the derivative : {} ".format(expr1_diff.doit()))
x = symbols('x')
expr2 = 1/x
# Use sympy.Derivative() method
expr2_diff = Derivative(expr2, x)
print("Derivative of expression with respect to x : {}".format(expr2_diff))
print("Value of the derivative : {} ".format(expr2_diff.doit()))
x = symbols('x')
expr3 = sin (x)
# Use sympy.Derivative() method
expr3_diff = Derivative(expr3, x)
print("Derivative of expression with respect to x : {}".format(expr3_diff))
print("Value of the derivative : {} ".format(expr3_diff.doit()))
x = symbols('x')
expr4 = cos (x)
# Use sympy.Derivative() method
expr4_diff = Derivative(expr4, x)
print("Derivative of expression with respect to x : {}".format(expr4_diff))
print("Value of the derivative : {} ".format(expr4_diff.doit()))
# Program 7
import sympy
from sympy import *
x, y= symbols('x y')
expr1=Eq(x+y-2,0)
expr2=Eq(2*x+y,0)
solve((expr1,expr2), (x, y))
sol_dict = solve((expr1,expr2), (x, y))
print(f'x = {sol_dict[x]}')
print(f'y = {sol_dict[y]}')
# Program 8
import sympy
from sympy import *
a1= symbols('x')
x1 = integrate('x**2',a1)
print("Integration of x: "+ str(x1))
a2= symbols('x')
x2 = integrate('sin (x)',a2)
print("Integration of sin (x): "+ str(x2))
a3= symbols('x')
x3 = integrate('cos (x)',a3)
print("Integration of cos (x): "+ str(x3))
# Program 9
import sympy as sym
from sympy import *
x = sym.symbols('x')
f = sym.Function('f')(x)
equation = Eq(f.diff(x,x)+ 9*f,1)
print(sym.dsolve(equation,f))
# Program 10
import sympy as sym
x,y,z = sym.symbols('x y z')
M = sym.Matrix(((3,7,-12,0),(4,-2,-5,0)))
system = A, b = M[:, :-1], M[:, -1]
print(sym.linsolve(system,x,y,z))