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

MEC 102 Homework #4 need answered before 4/18/2017 Problem overview Modify the o

ID: 3109669 • Letter: M

Question

MEC 102 Homework #4 need answered before 4/18/2017

Problem overview Modify the original codes that we developed for sin cos(x) and exp(x) (you can also refer to the "Additional Information") according the following design criteria: 1. (10 points) Make the calculations in the formof a callable function. Assume the argument x is in radians 2. (10 points) Include both help document (one line) and general help in your function 3. (90 points) For sin(x) and cos(x): a. Reduce the argument x, which originally can take the range of (-ootoo) to [0, 2T) using the modulo operator (b mood (a,m) b. Further reduce the argument from part (a) to [0, Tt/2) using relationships for sin(x) and cos(x) in the different quadrants of the circle. c. Call a sub-function to computethe value of the new, reduced argument from (a) and (b) above. The minimum argument value will be 0 and maximum will be Tu/2. 4. (50 points) For exp(x), separate the integer from the fractional component of the argument. For example if the function is called as exp(3.123), separate the 3 from the fractional component 0.123. Tip: you can use x-floor(x) to do this. Recognizing that exp(xty)Jexp(x) exp(y), compute the integer portion of the argument using a simple loop that performs the multiplication and calculate the fractional component using the series expansion. 5. (30 points) When calculating the infinite series (see HW #3 and lecture notes of Chapter 5 for the definitions of sin, cos, and exp), continue to calculate terms until the following accuracy condition is met: a. Save the current value of the series before another term is added. Call this, for example, b. Now add the new term and calculate the new value of the summation, Snew c. Determine the absolute value of the difference between the old and new te as d rms ISnew Sold I/Sold. d. Stop adding terms when the absolute value of the difference betwee Sola and Snew is n less than a prescribed value, e., d e. Use a 10 14 for all work in this assignment. 6. (10 points) Use the tic and toc functions to time your routines and compare their speed to the built in sin, cos and exp functions in matlab.

Explanation / Answer

s=1;
xt=1;
x=input('Enter a value for which exponent is to be found '); %The valuefor which the exponent function is executed
y=floor(x); %separates the integral and fractional part from the input. The integral part is assigned to this variable
fact=1;
N=input('Enter a value for N, must be an integer '); % Number of terms in the expansion. Better to have 15 or more for accuracy
for i=1:N
xt=xt*y;
fact=fact*i;
s=s+xt/fact;
end
disp(s); %The answer for the exponenent of the integral part.

s1=1;
xt=1;
yf=x-floor(x); % The fractional part is assigned to this variable.
fact=1;
for i=1:N
xt=xt*yf;
fact=fact*i;
s1=s1+xt/fact;
end
disp(s1); % The series sum for the fractional part
s2=s1*s;
disp(s2); % The series sum for the given input. SInce exp(x+y)=exp(x)*exp(y)

The editings in the code have been given appropriate explanation in the code.

SAMPLE TEST:

Enter a value for which exponent is to be found 6.23
Enter a value for N, must be an integer 15
403.2234

1.2586

507.4970

The program takes 6.23 as the input.

The first ouput is exp(6). The second output is exp(0.23) and the 3rd output is exp(6.23).