Where output goes when you run things within PyCharm depends on exactly how you run it and what options you have set for the virtual environment your code is running in. Your issue is likely to be difficult to diagnose from afar. Again, I suggest you try Jupyter, where the code apparently works.
Dr. Jonathan Gutow Halsey Science Room 412 Chemistry Department UW Oshkosh web: https://cms.gutow.uwosh.edu/Gutow e-mail: [email protected] Ph: 920-424-1326 On Jun 30, 2025, at 8:47 AM, Stephen Learmonth <[email protected]> wrote: I'm not getting any output at all. It shouldn't matter if I use PyCharm or Jupyter Notebook. The only thing that should matter is Python interpreter version, SymPy version, Numpy version and SciPy version. On Monday, 30 June 2025 at 14:31:41 UTC+1 [email protected] wrote: I use PyCharm for coding packages. I would not use it for this task. As has been suggested before, I encourage you to install Jupyter<https://jupyter.org/>, numpy, sympy and scipy. Then paste Peter’s code into a cell and run it. You will get cleaner output and it will be easier to keep track of what code has been run in a notebook. Dr. Jonathan Gutow Halsey Science Room 412 Chemistry Department UW Oshkosh web: https://cms.gutow.uwosh.edu/Gutow e-mail: [email protected] Ph: 920-424-1326<tel:(920)%20424-1326> On Jun 30, 2025, at 8:08 AM, Peter Stahlecker <[email protected]> wrote: I do not the the answer to your problem, I do not know what ``PyCharm Community Edition`` is. I get this output with your numbers: ``` time: 0.024225711822509766 message from root: The solution converged. error: [-4.44089210e-16 2.22044605e-16] w: 0.4474948009099584, b: -0.6156041430138662 ``` [email protected]<http://gmail.com/> schrieb am Montag, 30. Juni 2025 um 13:39:01 UTC+2: I have tried executing your code in PyCharm Community Edition but i get no output in the console. Nothing is printed to the console window. On Sunday, 29 June 2025 at 15:28:42 UTC+1 [email protected] wrote: m = 30 0..2 sec m = 40 1.0 sec m = 50 1.2 sec m = 60 1.6 sec m = 70 2.0 sec This is on my PC, which is a good, average PC [email protected] schrieb am Sonntag, 29. Juni 2025 um 16:08:15 UTC+2: Thanks. Can you give me a figure for execution time, when m = 30 say? Sent from my iPhone. On 29 Jun 2025, at 13:59, Peter Stahlecker <[email protected]> wrote: ``` # %% import numpy as np import sympy as sm from scipy.optimize import root m = 3 w, b = sm.symbols('w, b') x = [sm.symbols(f'x_{i}') for i in range(m)] y = [sm.symbols(f'y_{i}') for i in range(m)] def f(w, b, x, y): """Stephen's function""" m = len(x) if m != len(y): raise ValueError("x and y must have the same length") summe = sum([sm.sqrt((w**2 * x[i] - w * (y[i] - b))**2) / sm.cos(sm.atan((2 * w**2 * b - w * x[i] + y[i] + b) / (w**2 * x[i] - w * (y[i] - b)))) for i in range(m)]) return summe / m dfdw = f(w, b, x, y).diff(w) dfdb = f(w, b, x, y).diff(b) gleichung = sm.Matrix([[dfdw, dfdb]]) gleichung_lam = sm.lambdify((w, b, *x, *y), gleichung, cse=True) # %% # Set values x = [1.25, 2.0, 2.4] y = [1.75, 1.65, 2.85] if len(x) != m or len(y) != m: raise ValueError(f"x and y must have length {m}") def func(xx, args): w, b = xx[0], xx[1] return gleichung_lam(w, b, *args).squeeze() # Initial guess x0 = [1.043, -0.29] args = [*x, *y] # Iterate. This sometimes improves the result for _ in range(3): loesung = root(func, x0, args=args) x0 = loesung.x print("message from root:", loesung.message) print('error:', loesung.fun ) print(f"w: {loesung.x[0]}, b: {loesung.x[1]}") ```` This seems to work. I tried it for up to m = 75 NOTE: I replaced abs(a) with sqrt(a**2) as this 'behaves' better numerically. [email protected] schrieb am Sonntag, 29. Juni 2025 um 14:21:11 UTC+2: Let me post a reviewed version of the equations to solve: [Screenshot 2025-06-29 at 13.19.38.png] On Sunday, 29 June 2025 at 12:25:54 UTC+1 [email protected] wrote: Clear. But you only give one equation: df(w,b; x, y) /dwdb = 0 Two equations are needed to try and solve for w, b. From: [email protected] <[email protected]> On Behalf Of Stephen Learmonth Sent: Sunday, June 29, 2025 1:20 PM To: sympy <[email protected]> Subject: Re: [sympy] How can I solve this complex math equation using SymPy? x(i) can be 1.25, 2.0, 2.4 and y(i) can be 1.75, 1.65, 2.85 for i = 1 to 3. initial guess for w is +1.043 and b = -0.29. On Sunday, 29 June 2025 at 11:33:14 UTC+1 [email protected] wrote: What woud be the range of x(i), y(i)? What could be good initial guesses for w, b? (Needed to solve numerically.) On Sun 29. Jun 2025 at 12:11, <[email protected]> wrote: If you can solve for $m = 3$ to start with that would be great. Sent from my iPhone. On 29 Jun 2025, at 11:02, [email protected] wrote: Yes, it is non-linear Closed-form or numerical. Thanks. Sent from my iPhone. On 29 Jun 2025, at 10:47, Peter Stahlecker <[email protected]> wrote: At first glance this looks nonlinear in w and in b. Do you think there exists a closed form solution, or are you looking for a numerical solution given the x(i), y(i)? On Sun 29. Jun 2025 at 11:33, Stephen Learmonth <[email protected]> wrote: <Screenshot 2025-06-29 at 10.31.04.png> -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sympy/7229acb9-c0c1-4ed4-89a4-ee1136ad673bn%40googlegroups.com<https://groups.google.com/d/msgid/sympy/7229acb9-c0c1-4ed4-89a4-ee1136ad673bn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sympy/CABKqA0YHe5GCWx8C6EiYA%3DuA1dCq1ij7dvrV%2Bfi22Pbe8L-W0A%40mail.gmail.com<https://groups.google.com/d/msgid/sympy/CABKqA0YHe5GCWx8C6EiYA%3DuA1dCq1ij7dvrV%2Bfi22Pbe8L-W0A%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sympy/40199A34-88AE-45E4-8CFD-F71AD2E216D7%40gmail.com<https://groups.google.com/d/msgid/sympy/40199A34-88AE-45E4-8CFD-F71AD2E216D7%40gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sympy/dcb4fb0e-c4c2-4d27-81dd-19b35c89a7c9n%40googlegroups.com<https://groups.google.com/d/msgid/sympy/dcb4fb0e-c4c2-4d27-81dd-19b35c89a7c9n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sympy/ee36cabb-1a69-4984-bc51-3539cdcb030fn%40googlegroups.com<https://groups.google.com/d/msgid/sympy/ee36cabb-1a69-4984-bc51-3539cdcb030fn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sympy/b5ab4d4d-83da-4685-be51-56e7a592474dn%40googlegroups.com<https://groups.google.com/d/msgid/sympy/b5ab4d4d-83da-4685-be51-56e7a592474dn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion visit https://groups.google.com/d/msgid/sympy/cacdd381-36a5-461e-a9cf-f3540a4b6bdfn%40googlegroups.com<https://groups.google.com/d/msgid/sympy/cacdd381-36a5-461e-a9cf-f3540a4b6bdfn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sympy/AB68A55D-C86F-49BA-9C59-B1A10AF29EA3%40uwosh.edu.
