Python Forum
Solving equation equal to zero: How to resolve the syntax error?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solving equation equal to zero: How to resolve the syntax error?
#1
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
Reply
#2
Misspelled variable names (et0_ and ph0b). Unmatched parenthesis (missing closing parenthesis somewhere in the Eq). A return statement outside a function.
alexfrol86 likes this post
Reply
#3
(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
Reply
#4
You can only use return inside a function.
alexfrol86 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question written RK solving same equation with different graphs acbshinn 1 342 Feb-09-2024, 12:33 PM
Last Post: Gribouillis
  Syntax error for "root = Tk()" dlwaddel 15 1,013 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 334 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,452 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,137 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  [split] How to resolve version conflicts in Python? atonalwilson 1 952 May-04-2023, 09:02 AM
Last Post: buran
  How to resolve version conflicts in Python? taeefnajib 0 873 Apr-27-2023, 08:37 PM
Last Post: taeefnajib
  syntax error question - string mgallotti 5 1,251 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,194 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 847 Dec-05-2022, 06:38 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020