Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Taylor series expansion A Taylor series expansion of a function y f(x) is a very useful and common approximation concept in engineering. It is also
Taylor series expansion A Taylor series expansion of a function y f(x) is a very useful and common approximation concept in engineering. It is also used to actually program built-in functions in programming languages such as MATLAB. It is a power series according to (x - a)3 f(x) == f(x = a) + _ f'(x = a) + (x - a)2 2! where a is arbitrary. The primes denote derivatives with respect to x evaluated at xa. In the special case a - 0, the expansion is called a McLaurin series. One hopes that consecutive terms contribute less and less to the sum. In that case one says the series converges. The expansions of some functions f(x) converge quickly, others slowly, and yet others not at all Applied to the cosine function one gets with a-0 coS x cosn)COS (sin 0) COs 0) + -cOS 1! 3! 4! You see that all terms with odd power vanish because sin 0 0 and that all terms with even powe is the negative sine with cos 0 1. If you keep adding to infinity you get the formul r switch sign because the derivative of the sine is the cosine and the derivative of the cosine (-1)n (2n)! 2n cosx 1 n=0 Clearly, a computer cannot do this, therefore the sum must be truncated somewhere. One hopes to have then a good approximation for f(x) Write a MATLAB user-defined function as a script file fTcos.m. Use the built-in factorial function first. If successful, create a user-defined factorial function act. m as discussed in class Call this function from fTcos.m. You may use the following template to get started. while error>conver function y cos(x) Taylor expansion of the cosine function % Taylor series is an infinite sum % successive terms become smaller and smaller % convert degrees to radians |count = icount + 1 set convergence criterion (projected accuracy) conver 1,0e-6 % at least 1 term needed, initialize the sum to first term sum 1 % count the number of terms icount 1 fprintf(???) n2-2* % save previous sum umold sum o alternatively: n2fact-factorial(n2); % built-in factorial function %n2fact ffact(n2); % homebrew n factorial function sum = sum + ??? fprintft%3i % 10.5fn ' 'icount, sum) error (sum sumold)/sumold; error ??? the while loop must start, therefore error222, tprintfi'using %1 terms: %1 0.5fn ,icount
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started