Skip to content

Commit

Permalink
q_9_BVP_Updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
subhasmannna875 committed Apr 24, 2024
1 parent b22c744 commit e4db703
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Q_9_B_boundary_value_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@
from scipy.integrate import solve_bvp
import matplotlib.pyplot as plt

# Define the function representing the differential equation
def ode(x, y):
y1, y2 = y #y1=y ,y2=y'
dydx = [y2, y2 * np.cos(x) - y1 * np.log(y1)] #define derivitive
return dydx
# define boundary condition
return np.vstack((y[1], y[1]*np.cos(x) - y[0]*np.log(y[0] + 1e-10))) # Add small positive offset

# Define the boundary conditions
def bc(ya, yb):
return np.array([ya[0] - 1, yb[0] - np.exp(1)])

# Define the range of x values where we want to solve the ODE
# Define the x values for integration
x = np.linspace(0, np.pi/2, 100)

# Initial guess for the solution
# Adjusted initial guess to ensure positivity of y1
y_guess = np.zeros((2, x.size))
y_guess[0] = 1 # Initialize y1 with a positive value

# Solve the boundary value problem
sol = solve_bvp(ode, bc, x, y_guess)

# Plot the solution
plt.plot(sol.x, sol.y[0], label='y(x)')
plt.plot(sol.x, sol.y[0], label='Solution')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Solution of y\'\' = y\' * cos(x) - y * ln(y)')
plt.title("Solution of y'' = y'cos(x) - yln(y)")
plt.grid(True)
plt.legend()
plt.grid()
plt.show()

2 comments on commit e4db703

@subhasmannna875
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q_9_B
python plot

@subhasmannna875
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
mathematca plot

Please sign in to comment.