SlideShare a Scribd company logo
For any help regarding Python Homework Help
visit : - https://www.pythonhomeworkhelp.com/,
Email :- support@pythonhomeworkhelp.com or
call us at :- +1 678 648 4277
1 Difference Equations
System 1: Consider the system represented by the following difference equation
where x th [n] and y[n] represent the n samples of the input and output signals,
respectively
1.1 Poles
Determine the pole(s) of this system.
number of poles: 2
list of pole(s): 3 and −1/2
1.2 Behavior
Does the unit-sample response of the system converge or diverge as n → ∞?
converge or diverge: diverge
Briefly explain.
System 2: Consider a different system that can be described by a difference equation of
the form
y[n] = x[n] + Ay[n − 1] + By[n − 2]
where A and B are real-valued constants. The system is known to have two poles, given
by 1/2 ±j 1/3 .
1.3 Coefficients
Determine A and B.
A = 1 B = -13/36
1.4 Behavior
Does the unit-sample response of the system converge or diverge as n → ∞?
converge or diverge: converge
Briefly explain.
2 Geometry OOPs
We will develop some classes and methods to represent polygons. They will build on
the following class for representing points.
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def distanceTo(self, p):
return math.sqrt((self.x - p.x)**2 + (self.y - p.y)**2)
def __str__(self):
return ’Point’+str((self.x, self.y))
__repr__ = __str__
2.1 Polygon class
Define a class for a Polygon, which is defined by a list of Point instances (its vertices).
You should define the following methods:
• __init__: takes a list of the points of the polygon, in a counter-clockwise order
around the polygon, as input
• perimeter: takes no arguments and returns the perimeter of the polygon
>>> p = Polygon([Point(0,0),Point(1,0),Point(1,1),Point(0,1)])
>>> p.perimeter()
4.0
class Polygon:
def __init__(self, p):
self.points = p
def perimeter(self):
p = self.points
n = len(p)
per = 0
for i in range(n):
per += p[i].distanceTo(p[(i+1)%n])
return per
2.2 Rectangles
Define a Rectangle class, which is a subclass of the Polygon class, for an axis-aligned
rectangle which is defined by a center point, a width (measured along x axis), and a
height (measured along y axis).
>>> s = Rectangle(Point(0.5, 1.0), 1, 2)
This has a result that is equivalent to
>>> s = Polygon([Point(0, 0), Point(1, 0), Point(1, 2), Point(0, 2)])
Define the Rectangle class; write as little new code as possible.
class Rectangle(Polygon):
def __init__(self, pc, w, h):
points = [Point(pc.x - w/2.0, pc.y - h/2.0),
Point (pc.x + w/2.0, pc.y - h/2.0),
Point(pc.x + w/2.0, pc.y + h/2.0),
Point(pc.x - w/2.0, pc.y + h/2.0)]
Polygon.__init__(self, points)
2.3 Edges
Computing the perimeter, and other algorithms, can be conveniently organized by
iterating over the edges of a polygon. So, we can describe the polygon in terms of
edges, as defined in the following class:
class Edge:
def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2
def length(self):
return self.p1.distanceTo(self.p2)
def determinant(self):
return self.p1.x * self.p2.y - self.p1.y * self.p2.x
def __str__(self):
return ’Edge’+str((self.p1, self.p2))
__repr__ = __str__
Assume that the __init__ method for the Polygon class initializes the attribute edges to
be a list of Edge instances for the polygon, as well as initializing the points.
Define a new method, sumForEdges, forthe Polygon class that takes a procedure as
an argument, which applies the procedure to each edge and returns the sum of the
results. The example below simply returns the number of edges in the polygon.
>>> p = Polygon([Point(0,0),Point(2,0),Point(2,1),Point(0,1)])
>>> p.sumForEdges(lambda e: 1)
def sumForEdges(self, f):
return sum([f(e) for e in self.edges])
2.4 Area
A very cool algorithm for computing the area of an arbitrary polygon hinges on the fact
that: The area of a planar non-self-intersection polygon with vertices (x0, y0), . . . ,(xn,
yn) is
where |M| denotes the determinant of a matrix, defined in the two by two case as:
Note that the determinant method has already been implemented in the Edge class. Use
the sumForEdges method and any other methods in the Edge class to implement an area
method for the Polygon class.
def area(self):
return 0.5*self.sumForEdges(Edge.determinant)
or def area(self):
return 0.5*self.sumForEdges(lambda e: e.determinant())
or
def aux(e): return e.determinant()
def area(self): return 0.5*self.sumForEdges(aux)
3 Signals and Systems
Consider the system described by the following difference equation:
y[n] = x[n] + y[n − 1] + 2y[n − 2] .
3.1 Unit-Step Response
Assume that the system starts at rest and that the input x[n] is the unit-step signal u[n].
Find y[4] and enter its value in the box below.
y[4] = 21
We can solve the difference equation by iterating, as shown in the following table.
n x[n] y[n − 1] y[n − 2] y[n]
0 1 0 0 1
1 1 1 0 2
2 1 2 1 5
3 1 5 2 10
4 1 10 5 21
3.2 Block Diagrams
The system that is represented by the following difference equation
y[n] = x[n] + y[n − 1] + 2y[n − 2]
can also be represented by the block diagram below (left).
It is possible to choose coefficients for the block diagram on the right so that the
systems represented by the left and right block diagrams are “equivalent”.1
Enter values of p0, p1, A, and B that will make the systems equivalent in the
boxes below
p0 = 2 A = 2/3 p1 = −1 B = 1/3
For the left diagram, Y = X + RY + 2R2Y so the system function is
For the right diagram,
The two systems are equivalent if
Equating denominators, p0p1 = −2 and p0 + p1 = 1, i.e., p0 = 2 and p1 = −1. Equating
numerators, A + B = 1 and p1A + p0B = 0, i.e., A = 2/3 and B = 1/3.
4 Robot SM
In Design Lab 2, we developed a state machine for getting the robot to follow
boundaries. Here, we will develop a systematic approach for specifying such state
machines.
We start by defining a procedure called inpClassifier, which takes an input of type
io.SensorInput and classifies it as one of a small number of input types that can then
be used to make decisions about what the robot should do next.
Recall that instances of the class io.SensorInput have two attributes: sonars, which is a
list of 8 sonar readings and odometry which is an instance of util.Pose, which has
attributes x, y and theta.
Here is a simple example:
def inpClassifier(inp):
if inp.sonars[3] < 0.5: return ’frontWall’
elif inp.sonars[7] < 0.5: return ’rightWall’
else: return ’noWall’
Next, we create a class for defining “rules.” Each rule specifies the next state, forward
velocity and rotational velocity that should result when the robot is in a specified current
state and receives a particular type of input. Here is the definition of the class Rule:
class Rule:
def __init__(self, currentState, inpType, nextState, outFvel, outRvel):
self.currentState = currentState
self.inpType = inpType
self.nextState = nextState
self.outFvel = outFvel
self.outRvel = outRvel
Thus, an instance of a Rule would look like this:
Rule(’NotFollowing’, ’frontWall’, ’Following’, 0.0, 0.0)
which says that if we are in state ’NotFollowing’ and we get an input of type
’frontWall’, we should transition to state ’Following’ and output zero forward and
rotational velocities.
Finally, we will specify the new state machine class called Robot, which takes a
start state, a list of Rule instances, and a procedure to classify input types. The
following statement creates an instance of the Robot class that we can use to
control the robot in a Soar brain.
r = Robot(’NotFollowing’,
[Rule(’NotFollowing’, ’noWall’, ’NotFollowing’, 0.1, 0.0),
Rule(’NotFollowing’, ’frontWall’, ’Following’, 0.0, 0.0),
Rule(’Following’, ’frontWall’, ’Following’, 0.0, 0.1)],
inpClassifier)
Assume it is an errorif a combination of state and input type occurs that is not covered
in the rules. In that case, the state will not change and the output will be an action with
zero velocities.
4.1 Simulate
For the input classifier (inpClassifier) and Robot instance (r) shown above, give the
outputs for the given inputs.
4.2 Charge and Retreat
We’d like the robot to start at the origin (i.e., x=0, y=0, theta=0), then move forward
(along x axis) until it gets within 0.5 meters of a wall, then move backward until it is
close to the origin (within 0.02 m), and then repeat this cycle of forward and
backward moves indefinitely. Assume that the robot never moves more than 0.01 m
per time step.
Write an input classifier for this behavior.
def chargeAndRetreatClassifier(inp):
if inp.sonars[3] < 0.5: return ’frontWall’ el
if inp.odometry.x < 0.02: return ’origin’
else: return ’between’
4.3 Robot instance
Write an instance of the Robot class that implements the charge-and-retreat behavior
described above. Make sure that you cover all the cases.
FB = Robot(’Forward’,
[Rule(’Forward’, ’between’, ’Forward’, 0.1, 0),
Rule(’Forward’, ’origin’, ’Forward’, 0.1, 0),
Rule(’Forward’, ’frontWall’, ’Reverse’, 0.0, 0),
Rule(’Reverse’, ’frontWall’, ’Reverse’, -0.1, 0.0),
Rule(’Reverse’, ’between’, ’Reverse’, -0.1, 0.0),
Rule(’Reverse’, ’origin’, ’Forward’, 0.0, 0.0)],
chargeAndRetreatClassifier)
4.4 Matching
Write a procedure match(rules, inpType, state) that takes a list of rules, an input type
classification, and a state, and returns the rule in rules that matches inpType and state if
there is one, and otherwise returns None.
def match(rules, inpType, state):
for r in rules:
if r.inpType == inpType and r.currentState == state: return
r return None
Complete the definition of the Robot class below; use the match procedure you defined
above. Recall that, at each step, the output must be an instance of the io.Action class; to
initialize an instance of io.Action, you must provide a forward and a rotational velocity.
If a combination of state and input type occurs that is not covered in the rules, remain
in the same state and output an action with zero velocity.
class Robot(sm.SM):
def __init__(self, start, rules, inpClassifier):
self.startState = start self.rules = rules
self.inpClassifier = inpClassifier
def getNextValues(self, state, inp):
inpType = self.inpClassifier(inp)
r = match(self.rules, inpType, state)
if r:
return (r.nextState, io.Action(r.outFvel, r.outRvel)
else:
return (state, io.Action(0, 0))
5 Feedback
Assume that the system function for H can be written as a ratio of polynomials in R with
constant, real-valued, coefficients. In this We investigate when The System H is equivalent
to the following feedback system
where F is also a ratio of polynomials in R with constant, real-valued coefficients.
Example 1: Systems 1 and 2 are equivalent when H = H1 =
Example 2: Systems 1 and 2 are equivalent when H = H2 =
5.1 Generalization
Which of the following expressions for F guarantees equivalence of Systems 1 and
2?
Enter FA or FB or FC or FD or None: FC
Let E represent the output of the adder. Then
Y = FE = F(X + Y)
Y − FY = FX
H − HF = F
H = F + HF
5.2 Find the Poles
Let H3 = Determine the pole(s) of H3 and the pole(s) of
Pole(s) of H3: -1/2 Pole(s) of 1/7
Substitute 1/ z for R in H3:
The denominator has a root at z = −1/2. Therefore there is a pole at −1/2.
Substitute H3 into FB3:
Now substitute 1/ z for R:
The denominator has a root at z = 1/7. Therefore there is a pole at 1/7.
5.3 SystemFunction
Write a procedure insideOut(H):
• the input H is a sf.SystemFunction that represents the system H, and
• the output is a sf.SystemFunction that represents
You may use the SystemFunction class and other procedures in sf:
Attributes and methods of SystemFunction class:
__init__(self, numPoly, denomPoly)
poles(self)
poleMagnitudes(self)
dominantPole(self)
numerator
denominator
Procedures in sf
sf.Cascade(sf1, sf2)
sf.FeedbackSubtract(sf1, sf2)
sf.FeedbackAdd(sf1, sf2) sf.Gain(c)
def insideOut(H): return sf.FeedbackAdd(H, sf.Gain(1))
or
return sf.SystemFunction(H.numerator,H.denominator-H.numerator)
Robot SM: Reference Sheet
In Design Lab 2, we developed a state machine for getting the robot to follow
boundaries. Here, we will develop a systematic approach for specifying such state
machines.
We start by defining a procedure called inpClassifier, which takes an input of type
io.SensorInput and classifies it as one of a small number of input types that can then be
used to make decisions about what the robot should do next.
Recall that instances of the class io.SensorInput have two attributes: sonars, which is a
list of 8 sonar readings and odometry which is an instance of util.Pose, which has
attributes x, y and theta.
Here is a simple example:
def inpClassifier(inp):
if inp.sonars[3] < 0.5: return ’frontWall’
elif inp.sonars[7] < 0.5: return ’rightWall’
else: return ’noWall’
Next, we create a class for defining “rules.” Each rule specifies the next state, forward
velocity and rotational velocity that should result when the robot is in a specified current
state and receives a particular type of input. Here is the definition of the class Rule:
class Rule:
def __init__(self, currentState, inpType, nextState, outFvel, outRvel):
self.currentState = currentState
self.inpType = inpType
self.nextState = nextState
self.outFvel = outFvel
self.outRvel = outRvel
Thus, an instance of a Rule would look like this:
Rule(’NotFollowing’, ’frontWall’, ’Following’, 0.0, 0.0)
which says that if we are in state ’NotFollowing’ and we get an input of type
’frontWall’, we should transition to state ’Following’ and output zero forward and
rotational velocities.
Finally, we will specify the new state machine class called Robot, which takes a start
state, a list of Rule instances, and a procedure to classify input types. The following
statement creates an instance of the Robot class that we can use to control the robot in a
Soar brain.
r = Robot(’NotFollowing’,
[Rule(’NotFollowing’, ’noWall’, ’NotFollowing’, 0.1, 0.0),
Rule(’NotFollowing’, ’frontWall’, ’Following’, 0.0, 0.0),
Rule(’Following’, ’frontWall’, ’Following’, 0.0, 0.1)],
inpClassifier)
Assume it is an errorif a combination of state and input type occurs that is not covered
in the rules. In that case, the state will not change and the output will be an action with
zero velocities.

More Related Content

What's hot (20)

PPT
Chap 6 c++
Venkateswarlu Vuggam
 
PDF
Multidimensional arrays in C++
Ilio Catallo
 
PDF
Python programming : Abstract classes interfaces
Emertxe Information Technologies Pvt Ltd
 
PDF
Arrays in C++
Ilio Catallo
 
DOC
C tech questions
vijay00791
 
PDF
Monoids - Part 1 - with examples using Scalaz and Cats
Philip Schwarz
 
PPTX
07. Arrays
Intro C# Book
 
PDF
Simple IO Monad in 'Functional Programming in Scala'
Philip Schwarz
 
PDF
C++ Course - Lesson 2
Mohamed Ahmed
 
PDF
Dive Into PyTorch
Illarion Khlestov
 
PDF
Introduction to python
Marian Marinov
 
PPTX
Chapter 2
application developer
 
PPTX
Very interesting C programming Technical Questions
Vanathi24
 
PDF
Resource wrappers in C++
Ilio Catallo
 
PPTX
Mechanical Engineering Homework Help
Matlab Assignment Experts
 
PDF
A taste of Functional Programming
Jordan Open Source Association
 
PPT
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Enthought, Inc.
 
PPTX
Python programing
hamzagame
 
PPT
Introduction to AspectJ
mukhtarhudaya
 
Multidimensional arrays in C++
Ilio Catallo
 
Python programming : Abstract classes interfaces
Emertxe Information Technologies Pvt Ltd
 
Arrays in C++
Ilio Catallo
 
C tech questions
vijay00791
 
Monoids - Part 1 - with examples using Scalaz and Cats
Philip Schwarz
 
07. Arrays
Intro C# Book
 
Simple IO Monad in 'Functional Programming in Scala'
Philip Schwarz
 
C++ Course - Lesson 2
Mohamed Ahmed
 
Dive Into PyTorch
Illarion Khlestov
 
Introduction to python
Marian Marinov
 
Very interesting C programming Technical Questions
Vanathi24
 
Resource wrappers in C++
Ilio Catallo
 
Mechanical Engineering Homework Help
Matlab Assignment Experts
 
A taste of Functional Programming
Jordan Open Source Association
 
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Enthought, Inc.
 
Python programing
hamzagame
 
Introduction to AspectJ
mukhtarhudaya
 

Similar to Quality Python Homework Help (20)

PPTX
Simulating robot movement for cleaning a room
Programming Assignment Helper
 
PDF
MSC-2013-12
Roman Zeyde
 
PDF
Module 4.pdf
VijayKumar886687
 
PPTX
Python Homework Help
Python Homework Help
 
PDF
Artificial Intelligence Practical Manual.pdf
priyanshi25121980
 
PPT
OOC in python.ppt
SarathKumarK16
 
PPT
Python - Classes and Objects, Inheritance
erchetanchudasama
 
PPT
08-classes-objects.ppt
UmooraMinhaji
 
PPT
08-classes-objects.ppt
ssuser419267
 
PDF
A Simple 3D Graphics Engine Written in Python and Allegro
snowfarthing
 
PDF
UiA Slam (Øystein Øihusom & Ørjan l. Olsen)
Øystein Øihusom
 
DOCX
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
priestmanmable
 
PDF
Sona project
Jagannath Swain
 
PPTX
Python Homework Help
Python Homework Help
 
PDF
Unit-7 Representation and Description.pdf
ssuserf35ac9
 
PPTX
Python Programming Homework Help.pptx
Python Homework Help
 
PPTX
Lecture 6 python oop (ewurc)
Al-Mamun Riyadh (Mun)
 
PPTX
Deep learning simplified
Lovelyn Rose
 
PDF
Lecture notes on hybrid systems
AOERA
 
PPTX
Creating Objects in Python
Damian T. Gordon
 
Simulating robot movement for cleaning a room
Programming Assignment Helper
 
MSC-2013-12
Roman Zeyde
 
Module 4.pdf
VijayKumar886687
 
Python Homework Help
Python Homework Help
 
Artificial Intelligence Practical Manual.pdf
priyanshi25121980
 
OOC in python.ppt
SarathKumarK16
 
Python - Classes and Objects, Inheritance
erchetanchudasama
 
08-classes-objects.ppt
UmooraMinhaji
 
08-classes-objects.ppt
ssuser419267
 
A Simple 3D Graphics Engine Written in Python and Allegro
snowfarthing
 
UiA Slam (Øystein Øihusom & Ørjan l. Olsen)
Øystein Øihusom
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
priestmanmable
 
Sona project
Jagannath Swain
 
Python Homework Help
Python Homework Help
 
Unit-7 Representation and Description.pdf
ssuserf35ac9
 
Python Programming Homework Help.pptx
Python Homework Help
 
Lecture 6 python oop (ewurc)
Al-Mamun Riyadh (Mun)
 
Deep learning simplified
Lovelyn Rose
 
Lecture notes on hybrid systems
AOERA
 
Creating Objects in Python
Damian T. Gordon
 
Ad

More from Python Homework Help (20)

PPTX
Python Homework Help
Python Homework Help
 
PPTX
Python Homework Help
Python Homework Help
 
PPTX
Python Homework Help
Python Homework Help
 
PPTX
Python Homework Help
Python Homework Help
 
PPTX
Python Homework Help
Python Homework Help
 
PPTX
Complete my Python Homework
Python Homework Help
 
PPTX
Introduction to Python Dictionary.pptx
Python Homework Help
 
PPTX
Basic Python Programming.pptx
Python Homework Help
 
PPTX
Introduction to Python Programming.pptx
Python Homework Help
 
PPTX
Introduction to Python Programming.pptx
Python Homework Help
 
PPTX
Introduction to Python Programming.pptx
Python Homework Help
 
PPTX
Introduction to Python Programming.pptx
Python Homework Help
 
PPTX
Introduction to Python Programming.pptx
Python Homework Help
 
PPTX
Introduction to Python Programming.pptx
Python Homework Help
 
PPTX
Introduction to Python Programming.pptx
Python Homework Help
 
PPTX
Python Homework Help
Python Homework Help
 
PPTX
Perfect Python Homework Help
Python Homework Help
 
PPTX
Python Homework Help
Python Homework Help
 
PPTX
Python Programming Homework Help
Python Homework Help
 
PPTX
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
 
Complete my Python Homework
Python Homework Help
 
Introduction to Python Dictionary.pptx
Python Homework Help
 
Basic Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Python Homework Help
 
Introduction to Python Programming.pptx
Python Homework Help
 
Python Homework Help
Python Homework Help
 
Perfect Python Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
 
Python Programming Homework Help
Python Homework Help
 
Python Homework Help
Python Homework Help
 
Ad

Recently uploaded (20)

PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 

Quality Python Homework Help

  • 1. For any help regarding Python Homework Help visit : - https://www.pythonhomeworkhelp.com/, Email :- [email protected] or call us at :- +1 678 648 4277
  • 2. 1 Difference Equations System 1: Consider the system represented by the following difference equation where x th [n] and y[n] represent the n samples of the input and output signals, respectively 1.1 Poles Determine the pole(s) of this system. number of poles: 2 list of pole(s): 3 and −1/2 1.2 Behavior Does the unit-sample response of the system converge or diverge as n → ∞? converge or diverge: diverge
  • 3. Briefly explain. System 2: Consider a different system that can be described by a difference equation of the form y[n] = x[n] + Ay[n − 1] + By[n − 2] where A and B are real-valued constants. The system is known to have two poles, given by 1/2 ±j 1/3 . 1.3 Coefficients Determine A and B. A = 1 B = -13/36 1.4 Behavior Does the unit-sample response of the system converge or diverge as n → ∞?
  • 4. converge or diverge: converge Briefly explain. 2 Geometry OOPs We will develop some classes and methods to represent polygons. They will build on the following class for representing points. class Point: def __init__(self, x, y): self.x = x self.y = y
  • 5. def distanceTo(self, p): return math.sqrt((self.x - p.x)**2 + (self.y - p.y)**2) def __str__(self): return ’Point’+str((self.x, self.y)) __repr__ = __str__ 2.1 Polygon class Define a class for a Polygon, which is defined by a list of Point instances (its vertices). You should define the following methods: • __init__: takes a list of the points of the polygon, in a counter-clockwise order around the polygon, as input • perimeter: takes no arguments and returns the perimeter of the polygon >>> p = Polygon([Point(0,0),Point(1,0),Point(1,1),Point(0,1)]) >>> p.perimeter() 4.0
  • 6. class Polygon: def __init__(self, p): self.points = p def perimeter(self): p = self.points n = len(p) per = 0 for i in range(n): per += p[i].distanceTo(p[(i+1)%n]) return per 2.2 Rectangles Define a Rectangle class, which is a subclass of the Polygon class, for an axis-aligned rectangle which is defined by a center point, a width (measured along x axis), and a height (measured along y axis). >>> s = Rectangle(Point(0.5, 1.0), 1, 2) This has a result that is equivalent to >>> s = Polygon([Point(0, 0), Point(1, 0), Point(1, 2), Point(0, 2)])
  • 7. Define the Rectangle class; write as little new code as possible. class Rectangle(Polygon): def __init__(self, pc, w, h): points = [Point(pc.x - w/2.0, pc.y - h/2.0), Point (pc.x + w/2.0, pc.y - h/2.0), Point(pc.x + w/2.0, pc.y + h/2.0), Point(pc.x - w/2.0, pc.y + h/2.0)] Polygon.__init__(self, points) 2.3 Edges Computing the perimeter, and other algorithms, can be conveniently organized by iterating over the edges of a polygon. So, we can describe the polygon in terms of edges, as defined in the following class: class Edge: def __init__(self, p1, p2): self.p1 = p1 self.p2 = p2 def length(self): return self.p1.distanceTo(self.p2)
  • 8. def determinant(self): return self.p1.x * self.p2.y - self.p1.y * self.p2.x def __str__(self): return ’Edge’+str((self.p1, self.p2)) __repr__ = __str__ Assume that the __init__ method for the Polygon class initializes the attribute edges to be a list of Edge instances for the polygon, as well as initializing the points. Define a new method, sumForEdges, forthe Polygon class that takes a procedure as an argument, which applies the procedure to each edge and returns the sum of the results. The example below simply returns the number of edges in the polygon. >>> p = Polygon([Point(0,0),Point(2,0),Point(2,1),Point(0,1)]) >>> p.sumForEdges(lambda e: 1) def sumForEdges(self, f): return sum([f(e) for e in self.edges])
  • 9. 2.4 Area A very cool algorithm for computing the area of an arbitrary polygon hinges on the fact that: The area of a planar non-self-intersection polygon with vertices (x0, y0), . . . ,(xn, yn) is where |M| denotes the determinant of a matrix, defined in the two by two case as: Note that the determinant method has already been implemented in the Edge class. Use the sumForEdges method and any other methods in the Edge class to implement an area method for the Polygon class. def area(self): return 0.5*self.sumForEdges(Edge.determinant) or def area(self): return 0.5*self.sumForEdges(lambda e: e.determinant())
  • 10. or def aux(e): return e.determinant() def area(self): return 0.5*self.sumForEdges(aux) 3 Signals and Systems Consider the system described by the following difference equation: y[n] = x[n] + y[n − 1] + 2y[n − 2] . 3.1 Unit-Step Response Assume that the system starts at rest and that the input x[n] is the unit-step signal u[n].
  • 11. Find y[4] and enter its value in the box below. y[4] = 21 We can solve the difference equation by iterating, as shown in the following table. n x[n] y[n − 1] y[n − 2] y[n] 0 1 0 0 1 1 1 1 0 2 2 1 2 1 5 3 1 5 2 10 4 1 10 5 21 3.2 Block Diagrams The system that is represented by the following difference equation y[n] = x[n] + y[n − 1] + 2y[n − 2] can also be represented by the block diagram below (left).
  • 12. It is possible to choose coefficients for the block diagram on the right so that the systems represented by the left and right block diagrams are “equivalent”.1 Enter values of p0, p1, A, and B that will make the systems equivalent in the boxes below p0 = 2 A = 2/3 p1 = −1 B = 1/3 For the left diagram, Y = X + RY + 2R2Y so the system function is For the right diagram,
  • 13. The two systems are equivalent if Equating denominators, p0p1 = −2 and p0 + p1 = 1, i.e., p0 = 2 and p1 = −1. Equating numerators, A + B = 1 and p1A + p0B = 0, i.e., A = 2/3 and B = 1/3. 4 Robot SM In Design Lab 2, we developed a state machine for getting the robot to follow boundaries. Here, we will develop a systematic approach for specifying such state machines. We start by defining a procedure called inpClassifier, which takes an input of type io.SensorInput and classifies it as one of a small number of input types that can then be used to make decisions about what the robot should do next.
  • 14. Recall that instances of the class io.SensorInput have two attributes: sonars, which is a list of 8 sonar readings and odometry which is an instance of util.Pose, which has attributes x, y and theta. Here is a simple example: def inpClassifier(inp): if inp.sonars[3] < 0.5: return ’frontWall’ elif inp.sonars[7] < 0.5: return ’rightWall’ else: return ’noWall’ Next, we create a class for defining “rules.” Each rule specifies the next state, forward velocity and rotational velocity that should result when the robot is in a specified current state and receives a particular type of input. Here is the definition of the class Rule: class Rule: def __init__(self, currentState, inpType, nextState, outFvel, outRvel): self.currentState = currentState self.inpType = inpType self.nextState = nextState self.outFvel = outFvel self.outRvel = outRvel
  • 15. Thus, an instance of a Rule would look like this: Rule(’NotFollowing’, ’frontWall’, ’Following’, 0.0, 0.0) which says that if we are in state ’NotFollowing’ and we get an input of type ’frontWall’, we should transition to state ’Following’ and output zero forward and rotational velocities. Finally, we will specify the new state machine class called Robot, which takes a start state, a list of Rule instances, and a procedure to classify input types. The following statement creates an instance of the Robot class that we can use to control the robot in a Soar brain. r = Robot(’NotFollowing’, [Rule(’NotFollowing’, ’noWall’, ’NotFollowing’, 0.1, 0.0), Rule(’NotFollowing’, ’frontWall’, ’Following’, 0.0, 0.0), Rule(’Following’, ’frontWall’, ’Following’, 0.0, 0.1)], inpClassifier) Assume it is an errorif a combination of state and input type occurs that is not covered in the rules. In that case, the state will not change and the output will be an action with zero velocities.
  • 16. 4.1 Simulate For the input classifier (inpClassifier) and Robot instance (r) shown above, give the outputs for the given inputs. 4.2 Charge and Retreat We’d like the robot to start at the origin (i.e., x=0, y=0, theta=0), then move forward (along x axis) until it gets within 0.5 meters of a wall, then move backward until it is close to the origin (within 0.02 m), and then repeat this cycle of forward and backward moves indefinitely. Assume that the robot never moves more than 0.01 m per time step.
  • 17. Write an input classifier for this behavior. def chargeAndRetreatClassifier(inp): if inp.sonars[3] < 0.5: return ’frontWall’ el if inp.odometry.x < 0.02: return ’origin’ else: return ’between’ 4.3 Robot instance Write an instance of the Robot class that implements the charge-and-retreat behavior described above. Make sure that you cover all the cases. FB = Robot(’Forward’, [Rule(’Forward’, ’between’, ’Forward’, 0.1, 0), Rule(’Forward’, ’origin’, ’Forward’, 0.1, 0), Rule(’Forward’, ’frontWall’, ’Reverse’, 0.0, 0), Rule(’Reverse’, ’frontWall’, ’Reverse’, -0.1, 0.0), Rule(’Reverse’, ’between’, ’Reverse’, -0.1, 0.0), Rule(’Reverse’, ’origin’, ’Forward’, 0.0, 0.0)], chargeAndRetreatClassifier)
  • 18. 4.4 Matching Write a procedure match(rules, inpType, state) that takes a list of rules, an input type classification, and a state, and returns the rule in rules that matches inpType and state if there is one, and otherwise returns None. def match(rules, inpType, state): for r in rules: if r.inpType == inpType and r.currentState == state: return r return None Complete the definition of the Robot class below; use the match procedure you defined above. Recall that, at each step, the output must be an instance of the io.Action class; to initialize an instance of io.Action, you must provide a forward and a rotational velocity. If a combination of state and input type occurs that is not covered in the rules, remain in the same state and output an action with zero velocity. class Robot(sm.SM): def __init__(self, start, rules, inpClassifier): self.startState = start self.rules = rules self.inpClassifier = inpClassifier
  • 19. def getNextValues(self, state, inp): inpType = self.inpClassifier(inp) r = match(self.rules, inpType, state) if r: return (r.nextState, io.Action(r.outFvel, r.outRvel) else: return (state, io.Action(0, 0)) 5 Feedback Assume that the system function for H can be written as a ratio of polynomials in R with constant, real-valued, coefficients. In this We investigate when The System H is equivalent to the following feedback system
  • 20. where F is also a ratio of polynomials in R with constant, real-valued coefficients. Example 1: Systems 1 and 2 are equivalent when H = H1 = Example 2: Systems 1 and 2 are equivalent when H = H2 = 5.1 Generalization Which of the following expressions for F guarantees equivalence of Systems 1 and 2? Enter FA or FB or FC or FD or None: FC Let E represent the output of the adder. Then Y = FE = F(X + Y) Y − FY = FX
  • 21. H − HF = F H = F + HF 5.2 Find the Poles Let H3 = Determine the pole(s) of H3 and the pole(s) of Pole(s) of H3: -1/2 Pole(s) of 1/7 Substitute 1/ z for R in H3: The denominator has a root at z = −1/2. Therefore there is a pole at −1/2. Substitute H3 into FB3:
  • 22. Now substitute 1/ z for R: The denominator has a root at z = 1/7. Therefore there is a pole at 1/7. 5.3 SystemFunction Write a procedure insideOut(H): • the input H is a sf.SystemFunction that represents the system H, and • the output is a sf.SystemFunction that represents You may use the SystemFunction class and other procedures in sf: Attributes and methods of SystemFunction class:
  • 23. __init__(self, numPoly, denomPoly) poles(self) poleMagnitudes(self) dominantPole(self) numerator denominator Procedures in sf sf.Cascade(sf1, sf2) sf.FeedbackSubtract(sf1, sf2) sf.FeedbackAdd(sf1, sf2) sf.Gain(c) def insideOut(H): return sf.FeedbackAdd(H, sf.Gain(1)) or return sf.SystemFunction(H.numerator,H.denominator-H.numerator) Robot SM: Reference Sheet
  • 24. In Design Lab 2, we developed a state machine for getting the robot to follow boundaries. Here, we will develop a systematic approach for specifying such state machines. We start by defining a procedure called inpClassifier, which takes an input of type io.SensorInput and classifies it as one of a small number of input types that can then be used to make decisions about what the robot should do next. Recall that instances of the class io.SensorInput have two attributes: sonars, which is a list of 8 sonar readings and odometry which is an instance of util.Pose, which has attributes x, y and theta. Here is a simple example: def inpClassifier(inp): if inp.sonars[3] < 0.5: return ’frontWall’ elif inp.sonars[7] < 0.5: return ’rightWall’ else: return ’noWall’ Next, we create a class for defining “rules.” Each rule specifies the next state, forward velocity and rotational velocity that should result when the robot is in a specified current state and receives a particular type of input. Here is the definition of the class Rule:
  • 25. class Rule: def __init__(self, currentState, inpType, nextState, outFvel, outRvel): self.currentState = currentState self.inpType = inpType self.nextState = nextState self.outFvel = outFvel self.outRvel = outRvel Thus, an instance of a Rule would look like this: Rule(’NotFollowing’, ’frontWall’, ’Following’, 0.0, 0.0) which says that if we are in state ’NotFollowing’ and we get an input of type ’frontWall’, we should transition to state ’Following’ and output zero forward and rotational velocities. Finally, we will specify the new state machine class called Robot, which takes a start state, a list of Rule instances, and a procedure to classify input types. The following statement creates an instance of the Robot class that we can use to control the robot in a Soar brain.
  • 26. r = Robot(’NotFollowing’, [Rule(’NotFollowing’, ’noWall’, ’NotFollowing’, 0.1, 0.0), Rule(’NotFollowing’, ’frontWall’, ’Following’, 0.0, 0.0), Rule(’Following’, ’frontWall’, ’Following’, 0.0, 0.1)], inpClassifier) Assume it is an errorif a combination of state and input type occurs that is not covered in the rules. In that case, the state will not change and the output will be an action with zero velocities.