The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
****MATLAB PROBLEM*****
Â
Please help me complete the attacheLab 6: Taylor Series Using Loops ENGR-114 Prelab: Before starting your m-file, read through this entire document, then create a pseudocode flowchart of what your program will do using the standard symbols given in Section 8.2 of your textbook. Lab: Create a new m-file called taylor series.m that will contain a user-defined function. The function will have the function name, inputs, outputs, and help command information as shown. 1 f u n c ti o n [ con ve rge s , i t e r ] = . . . 2 t a y l o r s e r i e s ( func , x , e r ro r u b , m a x i t e r s ) 3 % Performs the Taylo r s e r i e s e xpan sion f o r e i t h e r the s i n e of x o r 4 % f o r Euler ’ s number r a i s e d to x . Func tion r e t u r n s whether o r 5 % not the f u n c ti o n co n v e rg e s wi t hi n the u se r−d efi n e d e r r o r u b 6 % wi t hi n m a x i t e r s i t e r a t i o n s . 7 % 8 % Inpu t : 9 % − func : A s t r i n g d e s c r i b i n g which f u n c ti o n to do the Taylo r 10 % s e r i e s e xpan sion on . ( ’ si n ’ f o r s i n e ( x ) , ’ exp ’ f o r e ˆx ) 11 % − x : Inpu t argument t ha t the f u n c ti o n w i l l o p e ra t e on . ( must be 12 % >= −50 and <= 50 ) 13 % − e r r o r u b : upper bound f o r e r r o r , o r maximum allow e d e r r o r 14 % ( a b s ol u t e val u e ) i n o r d e r to c o n si d e r the 15 % s e r i e s e xpan sion conve rged . ( must be >= 1e−12) 16 % − m a x i t e r s : User−d efi n e d maximum i t e r a t i o n s to t r y b ef o r e 17 % gi vi n g up . ( must be p o s i t i v e i n t e g e r <= 150 ) 18 % 19 % Output : 20 % − co n v e rg e s : e q u al s 1 i f s e r i e s conve rged to an e r r o r <= 21 % e r r o r u b wi t hi n m a x i t e r s o r l e s s , e l s e e q u al s 0 . 22 % − i t e r : i f co n v e rg e s i s 1 , e q ual to number of i t e r a t i o n s i t took 23 % to con ve rge wi t hi n e r ro r u b , e l s e e q u al s 0 . 24 % Underneath this, include a block comment with your name, the date, and the lab assignment number. Underneath that, create a function that fulfills the given description. Your function should verify that all four of its input variables have values as specified in the description, otherwise, use the error command to tell the user which variable is invalid and give the constraints. For example, if a user tries to call the function with x set equal to -60, this should trigger the following command. error(’x must be >= −50 and <= 50’) Your function should use a switch statement to verify the contents of the func variable. ©2016 Dan Kruger 1 1 of 2 Lab 6: Taylor Series Using Loops ENGR-114 The Taylor series for our two functions are below. e x = X∞ n=0 x n n! = 1 + x + x 2 2! + x 3 3! + x 4 4! + ... sin (x) = X∞ n=0 (−1)n x 2n+1 (2n + 1)! = x − x 3 3! + x 5 5! − x 7 7! + x 9 9! − ... Note that as n increases, each successive term gets smaller in absolute value. Knowing this, we can assert that if, for instance, the 10th term in a Taylor series is 0.005, then 10 iterations of the function will bring the sum of terms 1 through 10 to be within +/- 0.005 of the actual answer. In other words, 10 iterations yields an answer that has an error with absolute value of 0.005 or less. Your function shall use a while loop to compute each of these terms until the latest term’s absolute value is equal to or less than error ub. If/when the latest term in the Taylor series is within this boundary, use an if/break statement to exit the while loop. Otherwise, the while loop should keep running until it has been run max iters times. Note that your taylor series function will not be computing the sum of of these terms, nor will it be approximating the actual value of sin(x) or e x . You might find to be somewhat helpful. Some other recommendations: ˆExample 9.6 in your textbook shows how to use an if/break statement along with a flowchart of its algorithm. ˆStart working with your m-file as a regular script (not a function) with hard coded input values. This way you can easily run and re-run it for testing. ˆGet either the e x or the sin(x) capability working before adding the other capability. ˆOnce both of these capabilities are working, do the input validation for all of the input variables. ˆTest your code often! ˆWait until you have verified your function works, along with its input validation, before changing it into a function. ˆNow call your function from a separate m-file. It is easier to change values and re-run this way,v versus calling it from the command line each time. ˆVerify your results. Is your algorithm actually converging on a real solution? You can add in a variable that sums each term’s results and then compare it to the Matlab functions’ results for the two respective operations. Your instructor may provide some sample output file called ENGR114-Lab06-sample output.txt. Once you are satisfied that your file meets all the requirements, suppress all screen output, save the file, and submit it to appropriate D2L folder. ©2016 Dan Kruger 2 2 of 2d lab (skip the prelab). Thank you.
Attachments:
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly