Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 262729

Submitted on 18 Jun 2013 by Richard Zapor

Correct

74Size
Leading solution size is 44.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
d2=2;
Phi=pi/4;
d3=sqrt(2);
x1=d2-d3*cos(Phi);
y1=d3*sin(Phi);
Theta=atan(y1/x1);
d1=hypot(x1,y1);
[od2, oPhi]=solve_mirror(d1,d2+d3,Theta);
assert(abs(d2-od2)<.001)
assert(abs(Phi-oPhi)<.001)

                    
2
Pass
 
%%
d2=2;
Phi=1.5*pi/4;
d3=2;
x1=d2-d3*cos(Phi);
y1=d3*sin(Phi);
Theta=atan(y1/x1);
d1=hypot(x1,y1);
[od2, oPhi]=solve_mirror(d1,d2+d3,Theta)
assert(abs(d2-od2)<.001)
assert(abs(Phi-oPhi)<.001)
od2 =
     2
oPhi =
    1.1781
3
Pass
 
%%
d2=3;
Phi=.5*pi/4;
d3=1;
x1=d2-d3*cos(Phi);
y1=d3*sin(Phi);
Theta=atan(y1/x1);
d1=hypot(x1,y1);
[od2, oPhi]=solve_mirror(d1,d2+d3,Theta)
assert(abs(d2-od2)<.001)
assert(abs(Phi-oPhi)<.001)
od2 =
    3.0000
oPhi =
    0.3927
4
Pass
 
%%
d2=3+rand;
Phi=(.5+rand/10)*pi/4;
d3=1+rand;
x1=d2-d3*cos(Phi);
y1=d3*sin(Phi);
Theta=atan(y1/x1);
d1=hypot(x1,y1);
[od2, oPhi]=solve_mirror(d1,d2+d3,Theta)
assert(abs(d2-od2)<.001)
assert(abs(Phi-oPhi)<.001)
od2 =
    3.3204
oPhi =
    0.4497