14

exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,
Page 2: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,
exp(i2π/3), exp(-i2π/3)
vector
Page 3: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,
Page 4: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

2 } t l ?"rt tfl ?"W + /,tqta,, fr*/ HeildsI

Sn"t:* B}r t.P. fl1'ts

A t - z = E / l T = - / z /

= !" + k-z') 3ft') a(-t')T'= t

{tt-z)3!) dz ,,0,"n T (

tono,*l .oD T .

6")A

? d t T . = L - T 'ftt

J f t.) rlt-c) azT = o = r

JL ' - o

ftbf*,t c o

= &k1 rfs) = -'pb- T

0 S6p. St?^*t

C . F . P , t J = . A LeT. ?trt !' c

3 = |6 , c . U l ' ) =o a

"' ltP t

, ^fDiar-

f 6W P^fl\cl

j * 2 f * l = | u ; t l ' y r o ) = U f " ) = oA )a+z)+ l =o e 2=- l fu* - )e c = (

+ (4+*E):l + 1 3 , o g f " ) = o 4 A - B = o

l t = l - . * - t

Fts) 6(r)

U.:^dtt-t);z)

a*|"h hf* ,/f@f *f)- t - t , - t

= g - e - r C e

r - t= E e

N, l?.S" izoc o +. SGp r ' ,gor^t

Page 5: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

ll,t,^J f^t

Utt) = ; * ! . r3 ' "o.T z o

f .@-! lz lJ " * t J

eQ-')t- | ?Trry-)

t^)r,,;"'f t+,=r

L L c L - 1 J o

o-o ' f {L o t - l

t -+ .-'rt +L e + e - eo ( - l W

td)hs?

| / L 6 tt - += 1-Z

o 1 = l + t L e-t-et I

+ e - ee t

| - ct*# *"4 0

-+: 9 _

t

Lf -t t-r) - ' ( - t fr= l e T e d T = e J E J LJ ' o

o ^ _ +t L= C e

o( -)

X {!) [ + +e ,t - 9

, L '

- - -

rtlt*,-f,^,b",61'h" k6{I 5l+)

{Jg =3 [*)

.L

L ; " - tL f , , - , )

ft|fu, ,de / tkp;tJ

t ' b \g ' { " )

{ ' I f \t l

- x(b-a) _ze T e / T =

L

+ -nL -L("2-r)# f" + e

( o c - t ) -

- , r t / a - r . ' f r r . r \

e (u u di$ ''''{ ' oL )

_J

Page 6: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

{" (n) = L ' . -n '

a i" ln)_ -,3" b)

q" ( * ) = L./

Je & a e < ) |+ '

L

Exani,,'A Nfu

3fl- atto^^1;ts (*+ t 3L+ c'^l;/"b^) anft{2 6S?.

/t'{rft A^d^hfi^ tea,o^t .%^4 ^J'r*t * "6 o^,1 /;Jruost ( ;trurrrA\. C^nn stutJ4 aras tr'a/'irr"p''

&-,,^"" t e,nw, €rtr&:r Z"t i^ l| o( {r-,PfrU) d '^' fu:J A | , so' ;rn't

'c'xa[('

3*"r ,^ft e,'6a6ed , (,) (,^(ro1 t:"t,,|-,r .(^UITha2 *p il* (r",*"t) g/e) ; Q"t);' -?{tr) A'c;g,",f'c,*,! tu ̂ t"rr /u/n't neJ's Ar"t ft h)',,) v.{ ; .Ut ,,f- yt t.) , . ,,

Bt* 6i1 r[;) ettr*J "'obil q li^n?ffii\

Page 7: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

+ dA+" 4A^.t

L( t -^ t r ) a ,n , ttAT

l,L0 Cfi;^^J

t^.o c*nt (4) iv.'. -.

,l^fl,!4 L^ =

n'i(b

" + r c ) = zaA= I

ltt]l = Z, b^an^t, l ' " ' r A = l

+ I:ttoA;^^ttt = +1.2+d^^ttt_ i T _t i r . , A r , 1 lL t *i ,',t 'tt = Z- l- cttat IT f J . TL -A Jo

-L ( l- css'"t)

ft\fu' { ' l E ) =

{' hx* l^ntL h,o /eo-,t fu,u a {'lt) = t o^ artntt = l

^-fr- 0n = + feslr) - S/t -r) - trc+r] cmnt lt, l . )

_ I

= Z t t att ^T) tht'<e- Lrr ̂ Gr) '- a'^TT

Ao

Z -L ( t- (trtnT) *t ^t- - ' J \n t l

= * z ( t ' - d f , sn r ) * ^ t? - / r- A ft ^ = l

=) f ,/l) =

:) f/t-)

f xaru,,cl,3 t $ 1l\ a^rlz-!a-

6^UMrs J"*lbl

N 8 6 _ :fu*F

4-"d,^*

xs/f )

- Srulr) - SF-r)

6d/ le'"c^ 6;il;"frJ LJ

Page 8: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

A^" ,"n fu 1^r.Co^"'t**t, erfrf : -ftre t-f, af/ua/^ ,wrh * h/* q'

?*t /,eJ + c^rs aL*t' t{il04'

!'' ^Yf;,[::'7 )J ̂ nt &--o ,J.,:

+ (Z - t asn r )tn; 'v*t n,r*ot &ca*co 4* Z t til ; ri6dt o^ A'u l,il't

o( )',,bJ*tr'" i.r. ̂ h ,*'Lt ;" . Sl,.w.

J a;"s ,^ft, o^X"trel : n t in;.f;c,"t yr,n{* I/^^il ttr^ liln't rc^L\ tt^/ fr" p"f'^ /tr/dA {a;/

fr-t f ru) 'va drf -,1 dA -T ,t { ^:) r ne ̂ 2-z a slios - {tt) = E^ nf

P;'t = kNo, fie';6.,1 A' &^ffi * t '

J T < t < ' T= t f z * \ r y : h \ 4 A f u '

l;fr"- frL*t ̂ r 4 P+,Lra'bt^^A\ Wf il* .!r'*1"* ; fl'a

ot*t*t'r6k- ̂W"k il;*k^0 oL'ut '^I*t r

- l - 1 . I*lrr^ c2r1

h; I t * l = T-

\ , - - ' u

A : t

bn,a)tt

nh;frknt,

Page 9: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

\s) r-/ vrrt 9

fr u;^r)

A ̂ "sE*s

@l f,rl, {,ueJ /'*t n'isscs t--'U

. 2 +

+ { I ; .E i ) ; " G{ ' f+4.P. 4,,^(^ ,€-".''/&Llrt

v . + {

?xo-L*k Nlc

3Z+ "te*pt' (*r, /t 3L+) Anna6" I .f %

C^d;hf!^ rv,urdt,el fr^ y*t*

Cot.r,^-^*t 6 or t 'Tb^z b,4* t*db onJ

Br^^s ,^fr e"6"0rl' Cotbtoto. ,la,sbb^s.f wt bl^a, rtanl;d{n h^ftt ; G)'h)t {* rt/"): d1,'-

qe-/" l a 'Qi* *r*^t' & 6ft arts ..,Qtr t^t, "olr/t'rVa,*[.ra A6V, fr*^ | oa ruXfrgu /^:) ,'b 4ntttA

il"e gxa*,irvr

-h

Lb!n

Page 10: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

I

q 'Tol^;^1

s X - |

X4

s t + (

l l = t o A= L + C a

3

1) ,1 = 't/t o

r - 3l o

I-^Srt"* -l nnsd',''^t+ 3 X I

Q +-Lf+3

s2+ I, \ | =

S ? + t ) s + 3

+ B s + C

5t+ 2

tlw o.p tu(s /s= -r) aI

? "+ \ S 'o ) +6r"4*fi t s' ;'

s.* 2_ = 4 [s'* r) + (B s*c) (s+ 3)a | = f t + B a B = - 1 .

. , x = # # i , f u + * F t- - \ x l t ) = J L L - 3 r * I c a s t + 3 * t

lo ta ro

€Xo^ir*,s l./,83Zt ^ ttn ^fts ? 7% a*+z-Xz

A^m,* 1a^ Co. fr* [t*do"t'.3*;r ,,,k ̂ Ao6el ,'flrt" {k;+, il)* frd" ^ ,,ffi^nnt t 4bh

0^ us)^rt*s fu a.rnuxr /rr{h'J r7ht ws^oilg t*:lWLyh,r*, erotr ,ka did +^bt- ,"n,o oLtLtt x(o) = |

Page 11: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

(") fJ.r ,*

= O

.!^"t^: ) x = l d r * + . q ' = *

vr Sjru^oL;c t'^ 3

A sB f-d^$ ,,c.',ts :> g^ldb PG)c= l - - t I = *JT

f>o

t r o/ ' l ^x in^^ (a^ . f to ) n J=o x< l

f l i , rr ,*r^ (a^* f <o) ^ J=o x) |( > of>;f.o

tu ft+f

t =D x

StT^^"t= * 3 - t '

j r r ' - 7x

t+.ffi--Tr - F

3

hn^t V+ =o[ {

4+ *86

+ * 3 ' - 3 ' - + x + ** j ' - + ; Z t = L * 1 - L i

?3*<

"y( , )

> o

3 - ' o

)c

x

a €t t t " , ) c = l o - J = O

2L !

3 " ' - L x - 4 = o

, x = l + { / 3 o { / - J t 3T - 3

:

=

X = o7x

x =

t z O ,-" futniruun /+r, drfr-)( J /

U -- O c-a t*tc.Yi ttrlt^n ( ',

)

Page 12: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

t i ) ) c . r W?x

)L-- |

= O a 3 " = 3

t , J-'[ s"tdlt

= 6 x - L r y = Z x - L?$"

3 z J

A=r#ry,-w)'

a: ) q = : f - l ?' '.J J- \q)

Q{trtt-cI

:>j\

( . ) a+7x '2++

"'at3

s1 -^.[t:

, + o

exan *r's fU,tE3 L L

C*. w^ttrl rdtJ

f*^

&j3

Q")-29.-t

3t < o )

4 x 0 t L( < o )

I L( <o)

*r* r +rt+

(> ")- UrLr -Ul-

t > o )

:) l-ltil

:) Hfrx

o.*z--a-

1 x '

+(rq+

lro )zG0q-2m

K o )

,"l'x--1t

o Srleb

g^J/6

/:g o3

"frr*hts 6fl" a'&o1aenxr:Q| A,.firg.*q ax.tn /r'*sL a*/;fr,vs

'dr-ugf '= o or t

'Locln 'ar q

/'/#*= O

,Cxfnrrrvt* il"

r)Ap;wr- t*au1

B*^ ^ft *6"1'J' t3 * ' - * - L * =

f r k 1 ^ = 3 b= -t C,= - ]Qt*et ddtc

EillffnsTrdo

v

4,'-,rL,"/ 4.5-rt Gg'rt

Page 13: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

2011 Part IA Paper 4 Mathematical Methods J. Matheson

Section C Qu 11) a) Floating point numbers are expressed as an exponent and a mantissa, both stored in a fixed number of bits. The fixed number of bits for the exponent (IEEE single precision uses 8 bits) limits the range of numbers which can be represented and for the mantissa (IEEE single precision uses 23 bits representing 2-1 through 2-23) limits the precision. In this case it is the latter which is the problem as m gets gradually closer to 1 but without sufficient precision that t2 ever exactly equals x (tests for equality with floating point numbers are always dangerous). It will work for some values of x, but for others, m will become equal to 1 to the available precision before equality is achieved and the outer while loop will then loop for ever. b) Changing the outer loop from while (t2 != x) { to while (t2 != x && m > 1) { will fix the problem. c) If the function is passed a negative number almost everything goes wrong! First "if (x < 1)" is always true so we end up using the algorithm intended for |x| < 1. Next "while (t2 < x)" is never true so we simply apply the correction for overshooting and divide t by m and continue to do this for each successive value of m. So provided the outer loop terminates, which the correction in (b) will ensure, the value returned (which is 1/t) will be the product of the successive values of m (10, 5.5, 3.25, 2.125, etc) completely independently of x. Examiner's Comments: A generally well-answered question with candidates realising that the problem would have to do with the limited precision provided by the mantissa. Some were less good at spotting what line of code needed changing and some seemed to confuse “if” and “while”. The answer given to (c) is fuller than required by the wording of the question but no one noticed that t would be independent of x. An alternative in (b) is while (x - t2 > acc) { where acc is the achievable accuracy (and simplifies the answer to (c)!).

Page 14: exp(i2π/3), exp(-i2π/3) - University of Cambridgeteaching.eng.cam.ac.uk/system/files/P1A2011P004_1.pdf · a) Floating point numbers are expressed as an exponent and a mantissa,

Qu 12) a) Without structures we would need to represent the data as separate arrays for each of the fields within the structure, e.g. int refno[10000]; int mileage_start[10000]; etc ... and make sure by careful programming (throughout the program) that the i'th element of each of these arrays contained the data for the same car. With a structure, there is only the one array so this is guaranteed to be the case. Without structures we would have to pass each of fields separately to a function needing the attributes of a car rather than being able to pass the single data item of type car. b) bool needs_service (int refno) { int n; n = 0; while (ourcars[n].refno != refno) n = n + 1; if (ourcars[n].mileage_back >= ourcars[n].last_service + ourcars[n].service_interval) { return (true); else return (false); } c) O(n) Examiner's Comments: Some very good answers but some very minimal, producing a bi-modal mark distribution. A too common mistake in (a) was that using structures made things in some way easier for the computer (rather than the programmer) or greatly reduced the memory used. In (b) in a real program the while loop should contain protection against the refno not being in the array, i.e. while (n < num_cars && ourcars[n].refno != refno) but the question says we don't need to bother about this risk. And C++ would in fact allow return (ourcars[n].mileage_back >= ourcars[n].last_service + ourcars[n].service_interval); in place of the longer version given above.