0

Hey! I'm trying to solve an integration question but I keep on getting a long error.

from numpy import *
from sympy import *
from scipy.integrate import simps
a = 0 #bottom bound
b = pi/2 #upper bound
n = 200 #interval
dx = (b-a)/n #given in the activity
x_i=arange(0,pi/2+dx,dx)
y = sin(x_i)
y_i=(y+5)**(1/4)
S200=simps(y_i,x_i)

**This is the code, and the error that I get is below **

enter image description here

I tried solving the function that shouldve given me the solution using simpson's rule, but I got a long error.

  • Please post the error message as text, not as image. See: [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/). – AlexK Feb 27 '23 at 23:40

1 Answers1

0

You are running into a namespace collision because both numpy and sympy have a sin() function. Presumably, it's calling the sympy.sin() function because it was imported later than the numpy. You should in general avoid from package import * because these issues can occur. Also, I'm not sure what you're using the sympy package for.

import numpy as np
import sympy as sp
from scipy.integrate import simps
a = 0 #bottom bound
b = pi/2 #upper bound
n = 200 #interval
dx = (b-a)/n #given in the activity
x_i=np.arange(0,pi/2+dx,dx)
y = np.sin(x_i)
y_i=(y+5)**(1/4)
S200=simps(y_i,x_i)
Michael Cao
  • 2,278
  • 1
  • 1
  • 13