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

I am not really sure how to get started with this function.... What would be rea

ID: 3648295 • Letter: I

Question


I am not really sure how to get started with this function....




What would be reasonable to do (what students using this old book actually did!) if they needed sin(theta) for 31.233 degree s for example, but knew the values of the sine function only for a discrete set of degree s? Prelab exercise to be submitted via Blackboard. Assume that, values of the sine function, in the range 0 to 360 degree s, are tabulated in the array sin table for angles alpha n = n - 1 / k, n = 1,..,360k, where k is some known integer, k > 1. (The nth entry is sin(n - 1 / k). recall that in Matlab array indexing starts from 1). Write another Matlab function that gives you approximation to sin(x) with the resolution of 1 / k degree . Name your function NetId sinapp.m where Net Id is your Cornell net id. Use the following template. Things to remember: You must only work from the assumed tabulated values of sin(theta) for integer multiplies of theta = 1 / k (in degree s).

Explanation / Answer

In order to calculate to the some fixed degree of accuracy, ie – within , we must continue adding terms in the series until the approximation error is smaller than the desired accuracy. The following code illustrates this example: function y = sine_approx(x,error) format long; % This function approximates sin(x) using an infinite series expansion % up to some degree of accuracy. It is called (for example) as follows: % sine_approx(0.25*pi,0.0000000000001) y=x; n=1; remainder=0; real=sin(x); while(abs(y-real)>error) y = y +(-1)^n*(1/factorial(2*n+1))*x^(2*n+1); n_digits = abs(ceil(log10(abs(y-real)))); fprintf(['y = %16.',num2str(n_digits),'g '],y); n=n+1; end end To use this file, save it in MATLABs active directory, and call it command window (see below): >> sine_approx(0.25*pi,0.0000000000001) y = 0.7 y = 0.7071 y = 0.707106 y = 0.70710678 y = 0.70710678118 y = 0.7071067811866