Python Forum
Solving Equations with Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solving Equations with Python
#8
More on the problem...

I have been working also on other versions of the program. One of them, is the following one (going back to numpy, even if the precision and the ability to handle so many numbers or just long numbers, are not very good). The positive point of this version, is that at least prints (plots) the values (x, y), but not all of them are correct, as we can see clearly (check by running the program) that the values for 'y' seem to be correct, going through a range from '0' to '18' as line 7 indicates:
y = np.arange(0,18,.01)
but for the values of 'x', they all seem to be changed to '1'. I still have to find out why, and to correct it:
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(4,12,.01)
bigx = len(x)
print("\nThe matrix 'x' has", bigx, "elements.")
y = np.arange(0,18,.01)
ynumbers = [y]
bigy = len(y)
print("The matrix 'y' has", bigy, "elements.")
mother_of_matrices = bigx*bigy
print("Therefore, the interaction of matrices 'x' and 'y' produces a huge matrix of:", mother_of_matrices, "elements.")
k = 10/(6+x)

print('\n\nThese are the values for "x":\n\n', x)
print('\n\nThese are the values for "y":\n\n', y)
print('\n\nThese are the values for "k":\n\n', k)

for y in ynumbers:
        validynumbers = list(filter(lambda k: (1-k) != 0 and k != 0, k))
        for k in k:
            x = ((y**(1/k)-(y-6)**(1/k))/6)**(k/(1-k))
            plt.scatter(x,y)
            plt.show()

I tried to avoid problems related to dividing by '0' (or values of 'k' that seem to produce powers and fractions difficult to be handled by numpy), by adding line 20:
validynumbers = list(filter(lambda k: (1-k) != 0 and k != 0, k))
which filters the values of 'k' equal to '0' or that makes (1-k) = 0.
Nevertheless, it still gives us a warning message (it lets the program run, but warns us about something, in this case, still problems with the value '0'):
Error:
Warning (from warnings module): File "C:/Users/User1/AppData/Local/Programs/Python/Python37/equations_16.py", line 22 x = ((y**(1/k)-(y-6)**(1/k))/6)**(k/(1-k)) RuntimeWarning: divide by zero encountered in double_scalars
All the best,

I have just noticed, trying to close the matplot window, before closing the Python 3.7.4 Shell window, that another matplot window pops up, showing values for 'y' from around '6' to around '18' and for values for 'x' from around '5' to around '40', which I think they are still incorrect, as the values for 'x', supposedly go from '4' to '12'.
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Messages In This Thread
Solving Equations with Python - by japrap - Sep-09-2019, 04:22 PM
RE: Solving Equations with Python - by japrap - Sep-09-2019, 07:31 PM
RE: Solving Equations with Python - by japrap - Sep-09-2019, 07:54 PM
RE: Solving Equations with Python - by newbieAuggie2019 - Sep-11-2019, 02:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  SOlving LInear Equations in Python(Symoy, NUmpy) - Coefficient Problem quest 3 1,751 Jan-30-2022, 10:53 PM
Last Post: quest
Heart how to solve complex equations in python HoangF 3 2,807 Dec-26-2021, 07:04 PM
Last Post: HoangF
  Python scipy odeint: solving with solution-dependent functions etienne 0 2,753 Jun-05-2020, 01:29 PM
Last Post: etienne
  Differential equations with initial condition in Python (change a working code) Euler2 1 1,841 May-29-2020, 04:06 PM
Last Post: Euler2
Star résolution numérique pour les équations de Lockta-Volterra en python Mohamed19 2 2,246 Jul-07-2019, 01:26 PM
Last Post: SheeppOSU
  Getting a desired vector from lsqr in python when solving a linear system SJ001 0 2,437 Feb-21-2019, 04:19 PM
Last Post: SJ001
  Asking for help in solving a single variable nonlinear equation using Python ! NDP 0 1,993 Feb-15-2019, 12:03 PM
Last Post: NDP

Forum Jump:

User Panel Messages

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