Exercises (session 5)
17 Pages
English

Exercises (session 5)

-

Downloading requires you to have access to the YouScribe library
Learn all about the services we offer

Description

ExercisesFOSSEEDepartment of Aerospace EngineeringIIT BombaySciPy 2010, Introductory tutorialsDay 1, Session 5FOSSEE (IIT Bombay) Exercises 1 / 16Problem 1Example codel = []t = []for line in open(’pendulum.txt’):point = line.split()l.append(float(point[0]))t.append(float(point[1]))plot(l, t, ’.’)Problem StatementTweak above code to plot ...

Subjects

Informations

Published by
Published 27 June 2011
Reads 159
Language English
OFSSEEI(TIBom
Exercises
FOSSEE
Department of Aerospace Engineering IIT Bombay
SciPy 2010, Introductory tutorials Day 1, Session 5
ab)yxEreicess1/16
Problem 1
Example code
l = [] t = [] for line in open( ’pendulum.txt’ ): point = line.split() l.append(float(point[0])) t.append(float(point[1])) plot(l, t, ’.’ )
Problem Statement Tweak above code to plot data in file pos.txt .
FOSSEE(IITBombay)Exercises2/61
Problem 1 cont...
FO
Label both the axes. What kind of motion is this? Title the graph accordingly. Annotate the position where vertical velocity is zero.
SSEEI(TIoBbmya)Exercises3/16
Problem 2
Plot points given x and y coordinates
In []: x = [3, 2, -2, 3] In []: y = [1, -3, 4, 1] In []: plot(x, y)
Line can be plotted using arrays of coordinates.
Problem statement Write a Program that plots a regular n-gon(Let n = 5).
FOSSEE(IITBombay)xEercises4/61
Problem 2
Plot points given x and y coordinates
In []: x = [3, 2, 2, 3] -In []: y = [1, -3, 4, 1] In []: plot(x, y)
Line can be plotted using arrays of coordinates.
Problem statement Write a Program that plots a regular n-gon(Let n = 5).
FOSSEE(IIToBbmya)xEercises4/16
Problem
OFSSEEI(TIoBmbay)
3
Exercises
Damped Oscillation
In []: t = linspace(0, 4*pi) In []: plot(t, exp(t/10)*sin(t))
5/61
Problem 3 cont...
Create a sequence of images in which the damped oscillator( e t / 10 sin ( t ) ) slowly evolves over time t .
Hint
savefig( ’plot’ +str(i)+ ’.png’ )
OFSSEE(IITBombay)Exercises
#i
is
some
int
6/61
Problem 4
In []: In []: Out[]: In []: In []:
x = imread( smoothing.gif) x.shape (256, 256) imshow(x,cmap=cm.gray) colorbar()
Replace each pixel with mean of neighboring pixels
OFSSEE(IITBombay)Exercises7/16
FOSSEE
(IIT
Bombay)
Exercises
8
/
16
Problem 4: Approach
For y being resultant image:
y[1,
1]
Hint: Use array
=
x[0, 1]/4 + + x[2, 1]/4
Slicing.
FOSSEE (IIT Bombay)
Exercises
x[1, 0]/4 + x[1, 2]/4
9 / 16
Solution
In In
In
FO
[]: []:
[]:
SSEE(IITB
y = zeros_like(x) y[1:-1,1:-1] = x[:-2,1:-1]/4 + x[2:,1:-1]/4 + x[1:-1,2:]/4 + x[1:-1,:-2]/4 imshow(y,cmap=cm.gray)
mobay)xEercises01/61