Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
0
02002students_internal
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cp
02002students_internal
Commits
c2d9c0ba
"git@lab.compute.dtu.dk:aia02506/public-exercise-material.git" did not exist on "41890a1b4594ae6addf5d3b9140582ab198fa0eb"
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
No related tags found
No related merge requests found
Changes
2
Show 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
class
Sin
:
"""
A class that represents the sinus-function, i.e. sin(x) where x can be any expression.
"""
class
Cos
:
"""
A class that represents the cosine-function, i.e. cos(x) where x can be any expression.
"""
class
Variable
:
"""
A class that represents a (named) variable such as ``x``, ``y``, ``x2``, etc.
"""
...
...
@@ -67,7 +65,6 @@ if __name__ == "__main__":
exp
=
sine
(
cosine
(
sine
(
sine
(
make_symbol
(
'
x
'
)))))
print
(
format_expression
(
exp
)
)
# print(format_expression(exp), "evaluated in x=0 is", evaluate(exp, 0) )
pass
from
sympy
import
sin
,
cos
,
symbols
,
evaluate
,
Symbol
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
class
Vector
:
"""
A class that represents a Vector, defined by the endpoint :math:`(x,y)`.
"""
def
make_vector
(
x
:
float
,
y
:
float
)
->
Vector
:
"""
Create a new Vector object with end-points :math:`(x,y)`.
...
...
@@ -30,7 +29,8 @@ def print_vector(v: Vector):
: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
:
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:
:param v2: The second vector,
: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
:
r
"""
Scale the vector :math:`\mathbf{v}` by a factor of :math:`s`.
...
...
@@ -59,7 +61,8 @@ def add(v1 : Vector, v2 : Vector) -> Vector:
:param v2: The second vector.
: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
:
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:
:param v2: The second vector.
: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
...
...
@@ -159,7 +163,7 @@ def intersect(l1: LineSegment, l2: LineSegment) -> Vector:
:param l2: Second line
: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.
"
)
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