Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions errorcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@


class Error:
def __init__(self, func):
""" Perform a error estimation of given function
and corresponding errors for the variables. """

def __init__(self, func: callable):
""" Constructer for the Error instance.
Parameters
----------
func: callable
Func (e.g. a physical Law) is the function,
to which the error estimation is to be calculated.
The Arguments used in func are automatticlay extraced using
the inspect library.

Returns
------
Error Instance

"""
# Get the arguments of the function
arg_names = inspect.getfullargspec(func).args
# Define the variables as regular Python variables
Expand All @@ -21,7 +38,7 @@ def __init__(self, func):
f_prime = self.f.diff(variable)
self.derivatives[str(variable)] = f_prime

def substitute(self, values):
def substitute(self, values: dict):
derivatives_sub = []
for variable in self.variables:
# Get the variable name as a string
Expand All @@ -36,7 +53,7 @@ def substitute(self, values):
derivatives_sub.append(derivative_str)
return " + ".join(derivatives_sub)

def latex_out(self, values):
def latex_out(self, values: dict):
latex_str = "\\begin{align*}\n"
latex_str += (
" &= \\Delta "
Expand Down Expand Up @@ -72,7 +89,7 @@ def latex_out(self, values):
latex_str += f" &= \\SI{{{float(result)}}}{{}}\n"
latex_str += "\\end{align*}\n\n"
return latex_str
def result(self, values):
def result(self, values: dict):
result = sum(
[
values[delta_name][0]
Expand Down