1. 1st question
  2. import numpy as np
  3.  
  4. A = np.matrix("8 -8 -2; 4 -3 -2; 3 -4 1")
  5.  
  6. print("A :", A)
  7.  
  8. ev1, ev2 = np.linalg.eig(A)
  9.  
  10. print("Eigen Values :", ev1)
  11. print("Eigen Vector :", ev2)
  12.  
  13. 3rd question
  14.  
  15. import math
  16.  
  17. eqn = input("Enter the function in terms of x (e.g., x**3 - x - 2): ")
  18. a = float(input("Enter interval start (a): "))
  19. b = float(input("Enter interval end (b): "))
  20. tol = float(input("Enter tolerance (e.g., 0.0001): "))
  21.  
  22. fa = eval(eqn, {"x": a, "math": math})
  23. fb = eval(eqn, {"x": b, "math": math})
  24.  
  25. if fa * fb >= 0:
  26. print("Root does not lie in this interval.")
  27. else:
  28. while (b - a) / 2 > tol:
  29. mid = (a + b) / 2
  30. f_mid = eval(eqn, {"x": mid, "math": math})
  31.  
  32. if f_mid == 0:
  33. break
  34. elif eval(eqn, {"x": a, "math": math}) * f_mid < 0:
  35. b = mid
  36. else:
  37. a = mid
  38.  
  39. print(f"\nApproximate Root: {((a + b) / 2):.5f}")
  40.  
  41. 5th question
  42.  
  43.  
  44.  
  45. x, y, z, w = 0.0, 0.0, 0.0, 0.0
  46.  
  47. n = 15
  48.  
  49. print(f"{'k':<4} {'x':<12} {'y':<12} {'z':<12} {'w':<12}")
  50.  
  51. for k in range(1, n+1):
  52.  
  53. x_new = (6 + y - 2*z) / 10
  54. y_new = (25 + x + z - 3*w) / 11
  55. z_new = (-11 - 2*x + y + w) / 10
  56. w_new = (15 - 3*y + z) / 8
  57.  
  58. x, y, z, w = x_new, y_new, z_new, w_new
  59.  
  60. print(f"{k:<4} {x_new:<12.4f}{y_new:<12.4f}{z_new:<12.4f}{w_new:<12.4f}")
  61.  
  62. 7th question
  63.  
  64. print("Choose M(x,y):")
  65. print("1. M = x*y")
  66. print("2. M = x + y")
  67.  
  68. m_choice = int(input("Enter your choice for M: "))
  69.  
  70. print("\nChoose N(x,y):")
  71. print("1. N = x**2/2")
  72. print("2. N = x - y")
  73.  
  74. n_choice = int(input("Enter your choice for N: "))
  75.  
  76.  
  77. def dM_dy(x):
  78. if m_choice == 1:
  79. return x
  80. elif m_choice == 2:
  81. return 1
  82.  
  83.  
  84. def dN_dx(x):
  85. if n_choice == 1:
  86. return x
  87. elif n_choice == 2:
  88. return 1
  89.  
  90.  
  91. x = 2
  92.  
  93. if dM_dy(x) == dN_dx(x):
  94. print("\nThe differential equation is Exact")
  95. else:
  96. print("\nThe differential equation is Not Exact")
  97.  
  98. 9th question
  99.  
  100.  
  101. from sympy import symbols, Function, dsolve, Eq
  102.  
  103. x = symbols('x')
  104. y = Function('y')
  105.  
  106. eq = Eq(y(x).diff(x, 2) - 8*y(x).diff(x) + 15*y(x), 0)
  107.  
  108. solution = dsolve(eq)
  109.  
  110. print("y =", solution.rhs)