Skip to content
Snippets Groups Projects
Commit c2d9c0ba authored by tuhe's avatar tuhe
Browse files

Minor updates before week 3+4 review on the 24th

parent 8b929911
No related branches found
No related tags found
No related merge requests found
...@@ -4,11 +4,9 @@ import math ...@@ -4,11 +4,9 @@ import math
class Sin: class Sin:
"""A class that represents the sinus-function, i.e. sin(x) where x can be any expression.""" """A class that represents the sinus-function, i.e. sin(x) where x can be any expression."""
class Cos: class Cos:
"""A class that represents the cosine-function, i.e. cos(x) where x can be any expression.""" """A class that represents the cosine-function, i.e. cos(x) where x can be any expression."""
class Variable: class Variable:
"""A class that represents a (named) variable such as ``x``, ``y``, ``x2``, etc.""" """A class that represents a (named) variable such as ``x``, ``y``, ``x2``, etc."""
...@@ -67,7 +65,6 @@ if __name__ == "__main__": ...@@ -67,7 +65,6 @@ if __name__ == "__main__":
exp = sine(cosine(sine(sine(make_symbol('x'))))) exp = sine(cosine(sine(sine(make_symbol('x')))))
print( format_expression(exp) ) print( format_expression(exp) )
# print(format_expression(exp), "evaluated in x=0 is", evaluate(exp, 0) ) # print(format_expression(exp), "evaluated in x=0 is", evaluate(exp, 0) )
pass
from sympy import sin, cos, symbols, evaluate, Symbol from sympy import sin, cos, symbols, evaluate, Symbol
evaluate_expression = sin.evalf # Get the evaluation-function. Ignore the right-hand side for now. evaluate_expression = sin.evalf # Get the evaluation-function. Ignore the right-hand side for now.
......
...@@ -4,7 +4,6 @@ import matplotlib.pyplot as plt ...@@ -4,7 +4,6 @@ import matplotlib.pyplot as plt
class Vector: class Vector:
"""A class that represents a Vector, defined by the endpoint :math:`(x,y)`.""" """A class that represents a Vector, defined by the endpoint :math:`(x,y)`."""
def make_vector(x : float, y : float) -> Vector: def make_vector(x : float, y : float) -> Vector:
"""Create a new Vector object with end-points :math:`(x,y)`. """Create a new Vector object with end-points :math:`(x,y)`.
...@@ -30,7 +29,8 @@ def print_vector(v: Vector): ...@@ -30,7 +29,8 @@ def print_vector(v: Vector):
:param v: A vector object instance. :param v: A vector object instance.
""" """
print(f"{(v.x, v.y)}") # TODO: 1 lines missing.
raise NotImplementedError("print(.. format the print statement here .. )")
def dot(v1 : Vector, v2 : Vector) -> float: def dot(v1 : Vector, v2 : Vector) -> float:
r"""Compute the dot-product of ``v1`` and ``v2``, i.e. :math:`\mathbf{v}_1 \cdot \mathbf{v}_2`. r"""Compute the dot-product of ``v1`` and ``v2``, i.e. :math:`\mathbf{v}_1 \cdot \mathbf{v}_2`.
...@@ -39,7 +39,9 @@ def dot(v1 : Vector, v2 : Vector) -> float: ...@@ -39,7 +39,9 @@ def dot(v1 : Vector, v2 : Vector) -> float:
:param v2: The second vector, :param v2: The second vector,
:return: The dot product of ``v1`` and ``v2`` (as a ``float``) :return: The dot product of ``v1`` and ``v2`` (as a ``float``)
""" """
return v1.x * v2.x + v1.y * v2.y # TODO: 1 lines missing.
raise NotImplementedError("Insert your solution and remove this error.")
return dot_product
def scale(s : float, v : Vector) -> Vector: def scale(s : float, v : Vector) -> Vector:
r"""Scale the vector :math:`\mathbf{v}` by a factor of :math:`s`. r"""Scale the vector :math:`\mathbf{v}` by a factor of :math:`s`.
...@@ -59,7 +61,8 @@ def add(v1 : Vector, v2 : Vector) -> Vector: ...@@ -59,7 +61,8 @@ def add(v1 : Vector, v2 : Vector) -> Vector:
:param v2: The second vector. :param v2: The second vector.
:return: Their sum :math:`\mathbf{v}_1+\mathbf{v}_2` :return: Their sum :math:`\mathbf{v}_1+\mathbf{v}_2`
""" """
return make_vector(v1.x + v2.x, v1.y+v2.y) vector_sum = make_vector(v1.x + v2.x, v1.y+v2.y)
return vector_sum
def sub(v1 : Vector, v2 : Vector) -> Vector: def sub(v1 : Vector, v2 : Vector) -> Vector:
r"""Subtract the two vectors ``v1`` and ``v2`` and return the difference as a ``Vector`` object. r"""Subtract the two vectors ``v1`` and ``v2`` and return the difference as a ``Vector`` object.
...@@ -68,7 +71,8 @@ def sub(v1 : Vector, v2 : Vector) -> Vector: ...@@ -68,7 +71,8 @@ def sub(v1 : Vector, v2 : Vector) -> Vector:
:param v2: The second vector. :param v2: The second vector.
:return: Their difference :math:`\mathbf{v}_1-\mathbf{v}_2` :return: Their difference :math:`\mathbf{v}_1-\mathbf{v}_2`
""" """
diff = add(v1, scale(-1, v2)) # TODO: 1 lines missing.
raise NotImplementedError("Remember that x - y = x + (-1) * y.")
return diff return diff
...@@ -159,7 +163,7 @@ def intersect(l1: LineSegment, l2: LineSegment) -> Vector: ...@@ -159,7 +163,7 @@ def intersect(l1: LineSegment, l2: LineSegment) -> Vector:
:param l2: Second line :param l2: Second line
:return: A ``Vector`` representing the point of intersection. :return: A ``Vector`` representing the point of intersection.
""" """
# TODO: 1 lines missing. # TODO: Code has been removed from here.
raise NotImplementedError("Insert your solution and remove this error.") raise NotImplementedError("Insert your solution and remove this error.")
return p return p
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment