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

MATLAB HELP..! Modify the original codes that we developed for sin(x), cos(x) an

ID: 3818566 • Letter: M

Question

MATLAB HELP..!

Modify the original codes that we developed for sin(x), cos(x) and exp(x) (you can also refer to the "Additional Information") according the following design criteria: 1. Make the calculations in the form of a callable function. Assume the argument x is in radians. 2. Include both help document (one line) and general help In your function. 3. For sin(x) and cos(x): a. Reduce the argument x. which originally can take the range of (-infinity, +infinity) to [0, 2 pi) using the modulo operator (b = mod(a, m)). b. Further reduce the argument from part (a) to (0, pi/2) using relationships for sin(x) and cos(x) in the different quadrants of the circle. c. Call a sub-function to compute the value of the new, reduced argument from (a) and (b) above. The minimum argument value will be 0 and maximum will be pi/2. 4. 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(x + y) = exp(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. 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, S_old. b. Now add the new term and calculate the new value of the summation, S_new. c. Determine the absolute value of the difference between the old and new terms as d = |S_new - S_old|/S_old. d. Stop adding terms when the absolute value of the difference between S_old and S_new is less than a prescribed value, i.e., d 0, -1 if x

Explanation / Answer

import java.util.Scanner;
open class Calculator {
open static void main(String[] args) {
Scanner input = new Scanner(System.in);
Maths = new Maths();
twofold answer = 0;
twofold inputA, inputB;
scorch administrator;
boolean done = false;
while (done == false) {
System.out.print("Please enter your whole: ");
inputA = input.nextDouble();
administrator = input.next().charAt(0);
inputB = input.nextDouble();
switch (administrator) {
case '+': answer = Maths.add(inputA, inputB);
break;
case '- ': answer = Maths.subtract(inputA, inputB);
break;
case '*': answer = Maths.multiply(inputA, inputB);
break;
case '/': answer = Maths.divide(inputA, inputB);
break;
case '^': answer = Maths.power(inputA, inputB);
break;
}
System.out.println(answer);
}
input.close();
}
}
open class Maths {
twofold add(double a, twofold b) {
twofold answer = a+b;
return reply;
}
twofold subtract(double a, twofold b) {
twofold answer = a-b;
return reply;
}
twofold multiply(double a, twofold b) {
twofold answer = a*b;
return reply;
}
twofold divide(double a, twofold b) {
twofold answer = a/b;
return reply;
}
twofold power(double a, twofold b){
twofold answer =a;
for (int x=2; x<=b; x++){
answer *= a;
}
return reply;
}
}