Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function, call it mySine that calculates the value of sine by using the

ID: 3792830 • Letter: W

Question

Write a function, call it mySine that calculates the value of sine by using the Maclaurin series to a specific number of significant figures of accuracy, n. Estimate the accuracy by using the relative error, return the value of sine and the number terms used to reach the significant figure required. function [sine n] = mySine (theta nSigFig) Input parameters: theta = the angle in radians nSigFig = accuracy to this number of significant figures output parameters: sine = value of sine as calculated by function mySine, to the number of significant figures n = the number of terms used.

Explanation / Answer

%matlab code

function [sine,n] = mySIne(theta, nSIgFig)
sine = 0;
error = 1;
n = 0;
while true
next = sine;
sine = sine + (power(-1,n)/factorial(2*n+1))*power(theta,2*n+1);
error = abs(sine - next);
n = n + 1;
if( error < power(10,-1*nSIgFig))
break;
end
end
end

theta = input('Enter angle in radians: ');
nSIgFig = input('Enter accuracy to this number of significant figures: ');
[sine,n] = mySIne(theta, nSIgFig)

%{
output:

Enter angle in radians: pi/3
Enter accuracy to this number of significant figures: 10
sine = 0.86603
n = 8

%}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote