Write a function call it mySine that calculates the value of

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.

Solution

%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

%}

 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. Es

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site