Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The problem is approximating the Maclaurin series for cosine using while/for loops. I am terrible at these, and I figure I have to generate at

The problem is approximating the Maclaurin series for cosine using while/for loops. I am terrible at these, and I figure I have to generate at least two loops; one loop to create a factorial function because I don't think the factorial function works in matlab grader, and the second to create the summation of terms for approximating the cosine series, but I don't know where to start coding. I'm a beginner at coding and any help or suggestions would be great. Thanks in advance.

image text in transcribedimage text in transcribed

(10 points) Problem 2.3 - Maclaurin series O solutions submitted (max: Unlimited) The Maclaurin series expansion for the cosine function is: x X4 X6 X8 COS X = 1 - 2 * 4! 6! 8! where x is in radians. This function can be used to approximate the cosine of x with increasing accuracy as terms are added to the summation. Write a function that accepts two scalar inputs in order): 1. A value for X (in radians) for the series approximation of cos(x). 2. The number of terms, N, to be uses in the approximation. Your function should generate the following three outputs (in order): 1. A column vector of the first N term(s) summations. Consider the first summation to be 1, the second summation to be 1 - * 2. A column vector of relative approximate error. The relative approximate error is calculated using (present approximation - previous approximation) / present approximation (not in percentage). Note: use the relative approximate error to be 1 for the first iteration, since there is no "previous approximation". 3. A column vector of the relative true error. The relative true error is calculated using (true value - present approximation) / true value. Use MATLAB's built-in cosine function for the true value. Supplemental Deliverables (2 points) For supplemental deliverables, you do not need to run your code in Matlab Grader. You have to turn in a hard copy of what is asked. Utilizing this function you wrote and run your code on Matlab for the following condition. Set up a while loop to evaluate cos(5/3) by continue adding terms until the relative approximate error to be less than 10-8. Print out the number of terms, N. Also print your output with 3 columns of numbers. First column is your approximation, second column is the relative approximate error. Third column is the relative true error. The number of rows will be determined by the stopping criteria of relative approximate error to be less than 10-8. Function Reset MATLAB Documentation NM in 1 function (output] = maclaurin(x,N) % Write your code here. % x is an input, measured in radians % N is an input, representing number of terms % Output should include 3 columns of numbers. First column is your approximation. % Second column is relative approximate error. Third column is relative true error. % Names of variables (output, X, N) can be changed. The name of fucntion (maclaurin) and order of variables cannot. output = end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Distinguish between filtering and interpreting. (Objective 2)

Answered: 1 week ago