Python Forum

Full Version: Solving equation equal to zero: How to resolve the syntax error?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

When solving a system of equations, I need to take into account an additional equation equal to zero. To include this equation, I use sympy.subs() method, but I get a syntax error. I cannot understand what mistake I have made. Warmly requesting your support to correct the error.

PS: Underlining is used because it is required to iterate through several values for each variable.

from sympy import *
from sympy import symbols

ht0, et0, y30_, ph0b_, y50_, y60_, y70_, y80_ = symbols('ht0 et0 y30_ ph0b y50_ y60_ y70_ y80_')
equation = Eq(ht0, (y50_ * et0_ * cos(y30_) / sqrt(ph0b) + y60_ * -et0 * sin(y30_) / sqrt(ph0b) + y70_ * sqrt(1 / ph0b) * et0 * sin(y30_) + y80_ * (sqrt(1 / ph0b) * (1 + et0 * cos(y30_)) * (1 + et0 * cos(y30_))**2) / ph0b**2)
ham0 = solve(equation.subs(ht0, 0))
return ham0
Misspelled variable names (et0_ and ph0b). Unmatched parenthesis (missing closing parenthesis somewhere in the Eq). A return statement outside a function.
(Feb-21-2022, 07:32 AM)deanhystad Wrote: [ -> ]Misspelled variable names (et0_ and ph0b). Unmatched parenthesis (missing closing parenthesis somewhere in the Eq). A return statement outside a function.

Thank you so much!
I have corrected 2 mistakes, but I still have an issue with return (return statement outside a function). I want to use return not for function, but to keep the results from this equation for next calcullations. Is it a wrong tactic? I do not want to use "print"

      for y70_ in np.arange(y70[1], y70[0], step):
        y80_ = funct_labt(y30_, y60_, y70_, y50_)
        function_gam(et0_, y30_, ph0b, y50_, y60_, y70_, y80_)
        
        ht0, et0, y30_, ph0b, y50_, y60_, y70_, y80_  = symbols('ht0 et0 y30_ ph0b y50_ y60_ y70_ y80_')
        equation = Eq(ht0, (y50_ * et0 * cos(y30_) / sqrt(ph0b) + y60_ * -et0 * sin(y30_) / sqrt(ph0b) + y70_ * sqrt(1 / ph0b) * et0 * sin(y30_) + y80_ * (sqrt(1 / ph0b) * (1 + et0 * cos(y30_)) * (1 + et0 * cos(y30_))**2) / ph0b**2))
        #Use sympy.subs() method
        ham0 = solve(equation.subs(ht0, 0))
        return ham0
You can only use return inside a function.