Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
0
02002students
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cp
02002students
Commits
c2d9c0ba
Commit
c2d9c0ba
authored
1 year ago
by
tuhe
Browse files
Options
Downloads
Patches
Plain Diff
Minor updates before week 3+4 review on the 24th
parent
8b929911
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cp/ex09/sinus.py
+0
-3
0 additions, 3 deletions
cp/ex09/sinus.py
cp/ex09/vector.py
+10
-6
10 additions, 6 deletions
cp/ex09/vector.py
with
10 additions
and
9 deletions
cp/ex09/sinus.py
+
0
−
3
View file @
c2d9c0ba
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
cp/ex09/vector.py
+
10
−
6
View file @
c2d9c0ba
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment