Skip to content

Commit

Permalink
Q_9_B_BVP_Using Scipy
Browse files Browse the repository at this point in the history
  • Loading branch information
subhasmannna875 committed Apr 23, 2024
1 parent f05b30c commit 8272687
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Q_9_B_boundary_value_problem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import numpy as np
from scipy.integrate import solve_bvp
import matplotlib.pyplot as plt

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
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

This comment has been minimized.

Copy link
@subhasmannna875

subhasmannna875 Apr 24, 2024

Author Owner

i uploded wrong code

x = np.linspace(0, np.pi/2, 100)

# Initial guess for the solution
y_guess = np.zeros((2, x.size))

# 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.xlabel('x')
plt.ylabel('y')
plt.title('Solution of y\'\' = y\' * cos(x) - y * ln(y)')
plt.legend()
plt.grid()
plt.show()

2 comments on commit 8272687

@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
mathematica 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.

Q_9_B
python plot

Please sign in to comment.