## Mathworks Interview Question for Development Support Engineers

• 0

Comment hidden because of low score. Click to expand.
0
of 0 vote

You can use Taylor series:
sin(x) = x / 1! - x^3 / 3! + x^5 / 5! - ...

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````//Taylor Series Approximation
double theta = 45; //45 degrees
double PIby180 = 3.14159265358979323846264338327950/180;
double x = theta*PIby180;
double sinx = x*(1 - (x*x)*(1 - (x*x)*(1 - (x*x)/(6*7) ) / (4*5) ) /(2*3) );
x = (theta+90)*PIby180;
double cosx = x*(1 - (x*x)*(1 - (x*x)*(1 - (x*x)/(6*7) ) / (4*5) ) /(2*3) );``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

const double PI = 3.14159265358979323846264338327950;
const double epsilon = 0.000000000000000000000000001;

//sinx = x - x^3/3! + x^5/5! - x^7/7! + x^9/9! - ...
//this is not for old-fashioned handhold calculator
double sine(double x){
x = x - 2 * PI * (int)((x + PI)/(2*PI)); //put x in the interval (-PI, PI]
double result = x;
flip = 1;
xsquare = x * x;
xexp = x;
fac = 1;
curOrder = 1;
double oldvalue = 0;
while (abs(result - oldvalue) > epsilon){
oldvalue = result;
flip = flip * -1;
fac = fac * (curOrder + 1) * (curOrder + 2);
curOrder += 2;
xexp *= xexp * xsqure;
result = result + flip * xexp / fac;
}
return result;
}

Comment hidden because of low score. Click to expand.
0

i think it should be xexp = xexp*xsquare;
perhaps you meant to write: xexp *= xsquare;

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.