In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +… cos(x)=1-1…
The following solution is suggested to handle the subject “In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +… cos(x)=1-1…“. Let’s keep an eye on the content below!
Question “In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +… cos(x)=1-1…”
In MATLAB
The value of cos(x) can be approximated using a Maclaurin series + +… cos(x)=1-1 2! 4! 6! Which can be expressed compactly as cos(x) = {(-1)+7 (2(k-1))! 00 2(k-1) k-1 Write Matlab code using a while loop that calculates cos(2) with 5 terms of Maclaurin series. Compare the value with the one calculated with a built-in function cos (2) in Matlab. The following is an expected output from your code: Using the Maclaurin series cos( 2.0) with 5 terms is -0.4159 The value of cos(x) using the built-in cos function is -0.4161
Answer
clc; clear;
Close to all
x = 2
k = 1;
sum = 0;
While (k = 5).
sum = sum + (-1)^(k-1)*(x^(2*(k-1)))/factorial(2*(k-1));
k = k+1;
End
val = cos(2)
fprintf (‘Using the Maclaurin Series cos(2.0), with 5 terms is: %0.4f,sum);
fprintf (‘The value cos(x), using the built-in function cos, is %0.4fn’;val
Search Files Section Compare Go to Insert fx Fil Comments % 9/% Indent 5 New Save Breakpoints Run Advance and Advance Run and Time Print FILE NAVIGATE factorial (2*(k-1)); 10 end 11 – val – cos (2); 13 – fprintf (‘Using the Maclaurin Series cos (2.0), the value of cos(x), using the built-in function cos is 30.4fn’, sum); 14 0001 -in cos is 30.4fn’, 15 0001; 13 fprintfffffffffffffffffffffff ‘n’, the built-in function is 30.4fn’, the built-in is 30.4f’, the value of the built-in cos(x) is 30.4fn’, the value is 30.4fn’, the built-in cos’, val); 15.0001
Conclusion
Above is the solution for “In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +… cos(x)=1-1…“. We hope that you find a good answer and gain the knowledge about this topic of engineering.