Open alejocp00 opened 1 year ago
[I transferred this issue from https://github.com/jazzband/help to the PrettyTable repo]
How are you calling Create_Table
? Please provide a self-contained script.
[I transferred this issue from https://github.com/jazzband/help to the PrettyTable repo]
How are you calling
Create_Table
? Please provide a self-contained script.
Hi :wave: , this is the full code that produce the error.
def Euler_Method(function, x, y, max, h, d):
coordinates = []
while(Less_Than(x, max) or Equal_To(x, max)):
# Save values
coordinates.append(round(y,d))
# Update y value
y = y+h*function(x, y)
# Update x value
x = x+h
return coordinates
import numpy as np
def Calculate(function, y, min, max, h_values, method, d, n):
result = {}
# Calculate x values
x_values = np.linspace(min, max, num=n)
# Calculate y values
y_value = y
for x in x_values[1:]:
# Here will all pairs of y and h values
y_h_list = []
# Calculate y value of the current x value according to each one h vale
for h in h_values:
# Selecting the method to use
if method == Method.EULER:
y_value = Euler_Method(function, x, y, max, h, d)[-1]
elif method == Method.EULER_IMPROVED:
y_value = Euler_Method_Improved(function, x, y, max, h, d)[-1]
elif method == Method.RUNGE_KUTTA:
y_value = Runge_Kutta_Method(function, x, y, max, h, d)[-1]
y_h_list.append((y_value, h))
result[x] = y_h_list
return result
I don't include anything related with the 'method' parameter, because I got the same error with or with out it.
from prettytable import PrettyTable
def Create_Table(values: dict, method):
table = PrettyTable()
# Selecting table title
if method == Method.EULER:
table.title = "Euler Method"
elif method == Method.EULER_IMPROVED:
table.title = "Euler Improved Method"
elif method == Method.RUNGE_KUTTA:
table.title = "Runge-Kutta Method"
# Initialize the field names with x tag
table.field_names = ["x"]
# Adding a row for each x value, stored as keys
for x in values:
# The first value of the row will be always the x value
row_temp = [x]
for y_h in values[x]:
# Add y value
row_temp.append(y_h[0])
column_name = "y (h={})".format(str(y_h[1]))
# Check if I need to add the current y(h) to the columns
if column_name not in table.field_names:
table.field_names.append(column_name)
# Add the full row created to the table
table.add_row(row_temp)
print(table)
# Define function
def function(x, y):
return x/(1+y**2)
values = []
# Define initial values
x = -1
y = 1
max = 1
# Define h values
h_list = [0.1, 0.02, 0.004, 0.0008]
# Define number of decimals
d = 5
# Define number of equidistant points
n = 10
# Calculate values
values = Calculate(function, y, x, max, h_list, Method.EULER, d, n)
# Create table.
Create_Table(values, Method.EULER)
There's no code there :)
There's no code there :)
Sorry for that, my pc don't handle very well the web explorer open with the vscode at the same time, and I accidentally click Close with comment
Is this my error or from PrettyTable?
What did you do?
What did you expect to happen?
Get a string value similar to
What actually happened?
What versions are you using?
Please include code that reproduces the issue.
The best reproductions are self-contained scripts with minimal dependencies.