Answered step by step
Verified Expert Solution
Question
1 Approved Answer
DESCRIPTION The purpose of this assignment is to learn how to use while loops and if statements to solve common mathematical expressions. ASSIGNMENT You must
DESCRIPTION The purpose of this assignment is to learn how to use while loops and if statements to solve common mathematical expressions. ASSIGNMENT You must enter your solution into the MATLAB Grader and verify that all assessments are met to receive full credit. Include comments in your code where applicable. PROCEDURE Part 2: Taylor Series Expansion of Cosine (-12-1 C05 ) = Write a script that uses a while loop to estimate the cosine of using the Taylor series expansion until the output is within +/-0.0001 of the actual value returned when using the cosine function in MATLAB. Assign the number of iterations through the while loop as variable n. Script Save C Reset ES MATLAB Documentation 1 %Title: LAB 2 Part 2 2 %Author: 3 XDate: 4 %Description: This script solves the cosine of pi using the Taylor series %expansion until the result is within a threshold of cos(pi) threshold = 0.0001; %set a threshold to determine when to stop the numerical approximation 8 expansion = 1; %set the initial value of the Taylor series expansion when n=0 9 n - ; %store the number of times through the while loop and the summation index 11 %add your code here 12 13 fprintf("%g iterations to estimate cos(pi) to +/-g ', n, threshold); %print the number of times through the while loop and the estimated cos(pi) Run Script ? Assessment: Submit threshold is properly set cos(pi) used for comparison WHILE loop used no FOR loops used correct Taylor series expansion result for cos(pi) correct number of iterations
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