Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
NDSU 2. Trigonometry and f(x)=0 ECE 111 Math 105: Trigonometry and f(x)=0 Introduction From Wikipedia, Trigonometry (from Greek trigonon, "triangle" and metron, "measure"[1]) is a branch of mathematics that studies relationships involving lengths and angles of triangles. The field emerged in the Hellenistic world during the 3rd century BC from applications of geometry to astronomical studies. www.Wikipedia.com Trigonometry is fundamental to electrical and computer engineering. Power is transmitted as a 60Hz sine wave Analysis of filters, such as the bass boost on your stereo, relies upon expressing an audio signal in terms of a sum of sinusoids, AC motors, such as a quad-copter motor, are driven by sinusoidal signals where the frequency of the sine wave determines the speed of the motor Analysis of systems described by differential equations (read: everything) depends upon being able to use complex numbers - which have their origin in sin() and cos() functions. Likewise, trigonometry may seem like an archaic topic which deals only with architecture and triangles. Actually, it's much more than that. sin(), cos(), tan() Trigonometry is the study of the unit circle. If you draw a unit circle and take a point an angle from the x-axis, then The x-coordinate of that point is cos The y-coordinate of that point is sin If you extend the line from the origin to the point on the unit circle to x=1, the length of the line to the x-axis is tan y 1 cos(q) tan(q) 0.5 sin(q) q 0 -1.5 -1 -0.5 -20 0.5 1 1.5 x 2 -0.5 -1 sin(), cos(), and tan() are all related to the unit circle 1 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 It you let the angle increase with time as t then you get a sine wave. In Matlab: >> >> >> >> >> >> t = [0:0.01:6]'; w = 1; x = cos(w*t); y = sin(w*t); plot(t,x,t,y) xlabel('Time (seconds)'); 1 rad/sec sine wave: cos(t) (blue) and sin(t) (red) Note that cos() and sin() go between -1 and +1. This isn't surprising since these are just the x and y coordinates as you go around the unit circle. The period of cos() and sin() is 2 (6.28 seconds). The default units for cos() and sin() is radians. If you want to use degrees, the conversion is 360 degrees = 2 radians cycle 1 second 1Hz 2 rad sec Pretty much, anything English isn't natural. You'll find in engineering that the math works out a lot nicer if you use natural units - such as radians. If you increase the frequency, you get a sine wave that is quicker. A 1Hz sine wave 2 rad sec looks like the following: >> >> >> >> >> w = 2*pi; x = cos(w*t); y = sin(w*t); plot(t,x,'b',t,y,'r') xlabel('Time (seconds)'); 2 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 1Hz Sine Wave: cos(6.28t) (blue) and sin(6.28t) (red) What also shouldn't be surprising is that if you plot cos() vs sin() you get a circle >> x = cos(w*t); >> y = sin(w*t); >> plot(x,y) cos(t) vs. sin(t) produces the unit circle It also shouldn't surprising that cos 2 t sin 2 t 1 That just says that the circle you're using has a radius of one. That's sort of the definition of cos() and sin(). Polar Coordinates Given any point, you can experss it in Cartesian coordinates with its x and y values: P = (x, y) You can also express this in polar form as 3 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 P = r y 1 (x, y) 0.5 r q 0 -1.5 -1 -0.5 -20 0.5 1 1.5 x 2 -0.5 -1 A point P can be expressed in Cartesian coordinates (x,y) or polar coordinates (r ) The conversion from one to the other is x r cos y r sin or r x2 y2 arctan y, x There are two arctan() functions in Matlab atan(y/x) returns the angle from -pi/2 to +pi/2 (-90 degrees to +90 degrees) atan2(y, x) returns the angle The problem with atan is that if both x and y are negative, the signs cancel. To get the actual angle, you need to use atan2() With polar coordinates, you can plot some pretty neat functions. 4-Leaf Clover: r cos 2 Matlab Code: >> >> >> >> >> q = [0:0.001:1]' * 2 * pi; r = cos(2*q); x = r .* cos(q); y = r .* sin(q); plot(x,y); 4 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 4-Leaf Clover: ECE 111 r cos 2 A spiral r In Matlab: >> >> >> >> >> q = [0:0.001:1]' * 2 * pi * 10; r = q; x = r .* cos(q); y = r .* sin(q); plot(x,y); Spiral: r 5 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 Lissajieu Figures: x cosa y sin3a 0 a 2 This is a lot more fun if you let vary with time (see video for this). The figure with 0 looks like the following: Lissajieu Figure: x = cos(a), y = sin(3a) To make it rotate, use the following code: >> a = [0:0.001:1]' * 2 * pi; >> for i=1:1000 phi = i/100; x = cos(a); y = sin(3*a + phi); plot(x,y); pause(0.01); end Complex Numbers In electrical engineering, we deal with sine waves extensively. The problem with sine waves is you really need two coordinates: cos() and sin(). To get around this, there's a thing called complex numbers. Any given point is expressed as its real part (x) and its complex part (y) P = a + jb To keep the two separate, a term 'j' is added to the second part (the y-coordinate). 'j' is defined as j 1 and (a, b) are defined as 6 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 a is the real part of P (think of it as the x-coordinate) b is the imaginary part of P (think of it as the y-coordinate). Complex numbers make moving around the (x,y) plane a lot simpler: you can express a point with a single (complex) variable. The Matlab functions associated with complex numbers are: j: 1 P = 2 + j*3; Input the point 2+j3 real(P) The real part of P: imag(P) The imaginary part of P: abs(P) The magnitude of P: angle(P) The angle of P in radians the x-coordinate the y-coordinate the radius in polar coordinates You can also express any point in the complex plane in rectangular and polar form P x jy r x r cos y r sin r x2 y2 arctany/x Fun with Complex Numbers: Shoot Game Using complex numbers can make some computations a lot simpler. For example, write a MATLAB program to launch a cannon ball. Assume: The position of the cannon ball at any given time be P = x + jy. The real part of P is the X coordinate, the imaginary part of P is the y-coordinate. This initial position of the cannon ball is at the origin: P(t=0) = 0+j0 The initial velocity at t = 0 is v(t=0) = r Gravity pulls down with a force of 9.8 m/s2 The ground is flat: when the imaginary part of P goes negative, you hit the ground. Numerically, you can solve this easily in Matlab. At any given time, the acceleration is 9.8 m/s2 downwards: a(t) = 0 - j*9.8 7 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 Velocity is the integration of acceleration. Assuming a sampling rate of dt seconds v(t + dt) = v(t) + a(t)*dt Position is the integration of velocity P(t + dt) = P(t) + v(t)*dt Iterate over and over and you get the position of the cannon ball vs. time. Matlab Code: Angle = 45 * pi/180; Speed = 30; Target = 90 + j*0; P = 0 + j*0; v = Speed*( cos(Angle) + j*sin(Angle) ); a = 0 - j*9.8; dt = 0.01; while(imag(P) >= 0) v = v + a*dt; P = P + v*dt; clf plot([-1,100],[-1,50],'w.'); hold on; plot([-1,100],[0,0],'b-'); plot(real(Target), imag(Target), 'bx'); plot(real(P),imag(P),'ro'); pause(0.01); end 8 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 Resulting Display from Shooting a Cannon Ball with Initial Velocity = 30m/s at 45 degres elevation Now, assume there is wind drag. Wind is a cubic function opposing the direction of the velocity: f wind v 3 v Let be 0.0001. In Matlab: Angle = 45 * pi/180; Speed = 30; Target = 90 + j*0; P = 0 + j*0; v = Speed*( cos(Angle) + j*sin(Angle) ); dt = 0.01; while(imag(P) >= 0) wind = -( abs(v)^2 ) * v * 1e-4; a = wind - j*9.8; v = v + a*dt; P = P + v*dt; clf plot([-1,100],[-1,50],'w.'); hold on; plot([-1,100],[0,0],'b-'); plot(real(Target), imag(Target), 'bx'); plot(real(P),imag(P),'ro'); pause(0.01); end 9 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 Path of a cannon ball without wind drag (pink) and with wind drag (red) Solving f(x) = 0 This leads to another common problem you encounter in electrical and computer engineering: solving for a function equal to zero. Take the shoot game from above: determine the angle and speed which results in you hitting a target 90 meters out. There are several ways to do this: Interval Halving: Take one shot that's long and one that's short. Your next guess is the midpoint. Example: Shot #1: Speed = 30, Angle = 45 degrees. Error = -11.5287 ( it lands 11.5287 meters short of the target ) Shot #2: Speed = 40, Angle = 45 degrees. Error = +29.3160 ( it hits 29.3160 meters past the target ) Your next guess would be Shot #3: Speed = 35, Angle = 45 degrees Error = +9.2588 ( it hits 9.2588 meters past the target). Since the error is long, replace shot #2 (the long shot) with shot #3 and repeat. Your next guess would be Shot #4: Speed = 32.5, Angle = 45 degrees 10 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 30 Guess #2 (long) 25 20 15 10 Guess #3 (midpoint) 5 0 -5 -10 Guess #1 (short) -15 30 31 32 33 34 35 36 37 38 39 40 Interval Halving: Start with two guesses: one high, one low. The next guess is the midpoint. Keep iterating until the error is less than some threshold (0.1 meter here) California Method: Take one shot that's long and one that's short. Your next guess is interpolated between the two as X X 3 X 1 error E1 For example, with the above data, guess #3 would be 4030 11.5287 Speed 30 29.316011.5287 Speed 32.8226 This results in Shot #3: Speed = 32.8226, Angle = 45 degrees Error = +0.2876 ( it hits 0.2876 meters past the target ) Since this shot was long, replace the second shot with this one and repeat. Stop when you get close enough. 11 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 30 Guess #2 (long) 25 20 15 10 5 0 Guess #3 (interpolated zero crossing) -5 -10 Guess #1 (short) -15 30 31 32 33 34 35 36 37 38 39 40 California Method: Start with two guesses - one high the other low. Your next guess is interpolated between these two points. Newton's Method: Take one shot. Take another slightly faster. Based upon this, determine where the zero-crossing would be if it were a linear system. X 2 X 1 X e e 1 Example: Shot #1: Speed = 30, Angle = 45 degrees. Error = -11.5287 ( it lands 11.5287 meters short of the target ) Shot #2: Speed = 30.1, Angle = 45 degrees. Error = -11.1437 ( it hits 11.143729.3160 meters short of the target ) The next guess would then be 30.130 11.5287 Speed 30 11.143711.5287 Shot #3: Speed = 30.9952, Angle = 45 degrees. Error = +1.0139 ( it hits 1.0139 meters past of the target ) Repeat with this being shot #1. 12 December 23, 2016 NDSU 2. Trigonometry and f(x)=0 ECE 111 5 Guess #2 0 -5 -10 Guess #1 -15 29 30 31 32 33 Newton's Method: Start with a guess. Perturb this guess slightly to find the sensitivity. Your next guess is the zero crossing based upon these two. 13 December 23, 2016