Python Forum
Solving Equations with Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solving Equations with Python
#6
Hi again!

For what I have read, it seems that numpy doesn't work very well with huge amounts of data, so I thought of a way to go around it: I have modified the program to calculate the different solutions to your equation, by making a loop, calculating the solution for each value of 'y', for each value of 'x' and I got many solutions (too many to be printed here, but you can run the program on your own). Nevertheless, there are some warnings I noticed that I comment further down:

import numpy as np

x = np.arange(4,12,.01)
bigx = len(x)
print("\nThe matrix 'x' has", bigx, "elements.")
y = np.arange(0,18,.01)
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)



print('\n\nThese are the values for "x" in the equation:\n\n', x)
for x in x:
    for y in y:
        x = ((y**(1/k)-(y-6)**(1/k))/6)**(k/(1-k))
        print(x)


As I indicated above, due to some values (for instance, the '0' value), I got also two RuntimeWarning messages:

Error:
Warning (from warnings module): File "C:/Users/User1/AppData/Local/Programs/Python/Python37/equations_04.py", line 22 x = ((y**(1/k)-(y-6)**(1/k))/6)**(k/(1-k)) RuntimeWarning: invalid value encountered in power Warning (from warnings module): File "C:/Users/User1/AppData/Local/Programs/Python/Python37/equations_04.py", line 22 x = ((y**(1/k)-(y-6)**(1/k))/6)**(k/(1-k)) RuntimeWarning: divide by zero encountered in true_divide
and also this one at the end of the running time:
Error:
Traceback (most recent call last): File "C:/Users/User1/AppData/Local/Programs/Python/Python37/equations_04.py", line 21, in <module> for y in y: TypeError: 'numpy.float64' object is not iterable
I hope it helps,

Hi once again!

As you mention using a plot to display the pairs (x,y), I tried to do it with matplot, but it gives error warnings, but even so, it might give you some ideas:

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)
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)



print('\n\nThese are the values for "x" in the equation:\n\n', x)
for x in x:
    for y in y:
        x = ((y**(1/k)-(y-6)**(1/k))/6)**(k/(1-k))
        plt.scatter(x,y)
        plt.show()
and here are the errors related to scatter in matplot:

Error:
Traceback (most recent call last): File "C:/Users/User1/AppData/Local/Programs/Python/Python37/equations_06.py", line 24, in <module> plt.scatter(x,y) File "C:\Users\User1\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\pyplot.py", line 2847, in scatter None else {}), **kwargs) File "C:\Users\User1\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\__init__.py", line 1601, in inner return func(ax, *map(sanitize_sequence, args), **kwargs) File "C:\Users\User1\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\axes\_axes.py", line 4444, in scatter raise ValueError("x and y must be the same size") ValueError: x and y must be the same size
About previous warning messages, maybe you could make some exception commands to avoid dividing by '0', or to prevent encountering invalid values in power...

All the best,
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-09-2019, 09:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  SOlving LInear Equations in Python(Symoy, NUmpy) - Coefficient Problem quest 3 1,730 Jan-30-2022, 10:53 PM
Last Post: quest
Heart how to solve complex equations in python HoangF 3 2,789 Dec-26-2021, 07:04 PM
Last Post: HoangF
  Python scipy odeint: solving with solution-dependent functions etienne 0 2,739 Jun-05-2020, 01:29 PM
Last Post: etienne
  Differential equations with initial condition in Python (change a working code) Euler2 1 1,827 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,232 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,425 Feb-21-2019, 04:19 PM
Last Post: SJ001
  Asking for help in solving a single variable nonlinear equation using Python ! NDP 0 1,982 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