0

I want to write a program to ask for the values of Q,y,b,x,S0 then find the value of n from the following image

enter image description here

I used f solve to write this code:

from scipy.optimize import fsolve
def f(n,Q=float(input("Q=")),y=float(input("y=")),b=float(input("b=")),x=float(input("x=")),S_0=float(input("S0="))):
    return (1/n)*((y*(b+x*y))**(5/3))/((b+2*y*(1+x**2)**(1/2))**(2/3))*S_0-Q
a=fsolve(f,1)
print(a)
print(f(a))

But it gives a false result as output for my inputs here:

Q=21
y=7.645
b=2
x=1
S0=0.002
/usr/lib/python3/dist-packages/scipy/optimize/minpack.py:236: RuntimeWarning: The iteration is not making good progress, as measured by the 
  improvement from the last ten iterations.
  warnings.warn(msg, RuntimeWarning)
[ 1.]
[-20.68503025]

I wrote this in Online Python. I don't know what is the meaning of this error. also the output is wrong. answer should be n=0.015 for this specific input. how can I fix this code?

Etemon
  • 53
  • 2
  • 11

1 Answers1

1

I rearranged your equation, and this somehow gets your expected result. I'm really not quite sure what is the issue, sorry!

    return (S_0/Q)*((y*(b+x*y))**(5/3)/(b+2*y*(1+x**2)**(1/2))**(2/3))-n
user12758604
  • 375
  • 1
  • 9
  • Oh you are right. I was tricked by https://stackoverflow.com/questions/64400639/solve-an-implicit-equation-python by myself and thought it is implicit equation when n is unknown! – Etemon Feb 04 '21 at 06:08