Mathematical Algorithms in Matlab I
Mathematical Algorithms in Matlab I MATH 151
Popular in Course
Popular in Mathematics (M)
This 6 page Class Notes was uploaded by Melvina Keeling on Monday September 21, 2015. The Class Notes belongs to MATH 151 at Colorado State University taught by Staff in Fall. Since its upload, it has received 20 views. For similar materials see /class/210093/math-151-colorado-state-university in Mathematics (M) at Colorado State University.
Reviews for Mathematical Algorithms in Matlab I
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/21/15
COLOSTATE SPRING 2009 MATH 151 LECTURE 3 Plot Curves Secant Lines and Tangent Lines For the function fx sinx at 0 7T47 plot the secant lines through the points x07f0 and 0 h7fx0 h for h 12714718 and the tangent line to the function at 0 Z SecTanLinesm Z Courtesy of Dr Anton Betten Z Adopted by Jiangguo James Liu ColoState 012009 Clear all figure1 Z hold off X linspace0pi2101 y sinx a pi4 b sina for h 12 14 18 C a h d sinc slopesecant d bC a Xparam linspace 1111 yparam slopesecantxparam Z plota C b d ob plotx y 7 k aXparambyparam b title sinx at Xpi4 Xlabel x ylabel y axis tight Z setgcaXTick0 pi8 pi2 setgcaXTiCkLabel0pi8pi43pi2pi2 hold on end slopetangent cospi4 tangent slopetangentxparam plotaxparam btangent 7 r The Bisection Method for Finding Roots Description of the method For a given equation f 07 0 Choose given an interval 17 such that fafb lt 0 0 Let the initial guess be 1 a b2 0 Check 3 cases fx1 0 small enough7 fafz1 lt 077 fx1fb gt 0 Then respectively exit7 or set b 17 or set a 1 0 Next guess n1 a b2 now new Lab 0 Stop criteria 1 Threshold small enough7 say lt 10 9 2 Tolerance 1 and M close enough7 say lt 10 12 Use the following commandsfunctions abs7 if7 while end Use help or doc to get help on the commands functions that you want to use7 for example7 doc while ExamplesEquations 0 Equation of light diffraction z 7 tan 07 17 2 o Keplers equation m 7 2 sinx 17 717 3 0 Cubic equation 3 4x2 7 3 07 071 COLOSTATE SPRING 2009 MATH 151 LECTURE 2 Home Made 7139 Recall 1 717273 1 z Replacing x by 2 yields 17x2x47z6 1 2 lntegrating both sides leads to 1 d 1 1 1 Earctanl7arctan0O12 17 gi 7 which provides a simple formula for computing 7T 00 HomeMadePim 00 Use an alternating series to generate pi oo Jiangguo James Liu ColoState 012009 N input Type in a large positive odd integer 7 sum 0 sign 1 for k1z2zN sum sum sign1k sign sign end format long sum4 pi sum4 pi Related Exercise Use Matlab help to get yourself familiar with the functionscommands input7 for end7 format A Mathematical Dart Z MathDartm Z Courtesy of Dr Anton Betten Z Adopted by Jiangguo James Liu ColoState 012009 616 Clear all Close all rand seed 12345 Numberlnside 0 estimate zeros5001 for k1 500 X 1 2rand1001 y 1 2rand1001 Numberlnside Numberlnside sumx 2y 2lt1 estimatek Numberlnsidek1004 end plotestimate title darts Xlabel k ylabel COLOSTATE SPRING 2009 MATH 151 LECTURE 4 Newton7s Method for RootFinding Almost every nonlinear equation can be rewritten as f 07 where f is assumed to be a differentiable function We want to nd 0 a root of this equation 0 or a zero of the function 0 or an intersection of the curve with the x axis Let7s say7 an initial guess to the root is 0 The tangent line to the curve at point 07 f0 y fWo f0 0 The Main Idea Use the intersection of the tangent line with the s axis as an approximation to the intersection ofthe curve with the x axis Setting y 0 in the above tangent line equation7 we obtain f0 f oy assuming f x0 31 0 Of course7 in that case7 the tangent line is parallel to the x axis7 we wont have any intersection Keep doing so7 we establish an iterative scheme 95 9 m 7 V L 107 1 and this is the great Newton7s method Implementation of Newton7s Method Implement the Newton7s method as an independent function le that has the following format function aprxitr newtonfxnfxnderivtolmaxitrguess where aprx An approximation to the root itr The number of iterations executed fxn A generic function for the equation fxnderiv A generic function for the derivative tol A preset tolerance7 say 10 9 maxitr Maximal number of iterations allowed guess An initial guess to the root Things to Consider When Implementing the Newton7s Method 0 Use for end or while end for iterations 0 Use feval for the two generic functions fxn and fxnderiv 0 Store all successive approximations into a vector 0 Handle the exception case divided by zero Examples of using inline to de ne a function myfxn inline x 3 2X2 7X7 myfxnderiv inline 3x 2 2 7X7
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'