% T4.4-1 Given a number x and the quadrant q (q = 1, 2, 3, 4), write a program to compute sin^{ -1} (x) in degrees, taking into account the quadrant. The program should display an error message if |x|>1.
% A proposed solution is shown below.
% a) Make the program more readable by proper indentation of the statements.
% b) Do you agree with the solution and with the explanation given? If not, what changes would you make?
% c) convert  your (modified?) solution into a function that produces the output y, for inputs: x and q.
%
% Proposed Solution
% Note that the asin(x) function returns the correct value (in radians) only if x is in the first or fourth quadrant. Note also that it is possible to give incompatible values for q and x. For example, q cannot equal 1 if x<0. The following script file protects against this error.

if x >= 0&x<1
if q==1
y = asin(x)*180/pi
elseif q==2
y = asin(x)*180/pi + 270
end
if q==3|q==4
disp('Incompatible values of x and q')
else
disp(y)
end
elseif x<0&x>-1
if q==4
y = asin(x)*180/pi;
else
y = asin(x)*180/pi -90;
end
if q==1|q==2
disp('Incompatible values of x and q')
else
disp(y)
end
else
disp('The magnitude of x is greater than 1')
end

% P_4_3_12
% The height and speed of a projectile launched with a speed of v_0 at an angle A to the horizontal arev given by
%
% h(t) = v_ot\sin(A) - 0.5gt^2
% v(t) = \sqrt{v_o^2 - 2v_ogt\sin(A)+g^2t^2}
%
% where g is the acceleration due to gravity. The projectile will strike the ground when h(t) = 0, which gives the time to hit
% t_{hit} = 2 ( v_0/g)\sin( A).
% Suppose that A = 30°, v_0 = 40 m/s, and g = 9.81 m/s^2. Use the MATLAB relational and logical operators to find the times when
% a. The height is no less than 15 m.
% b. The height is no less than 15 m and the speed is simultaneously no greater than 36 m/s.
% c. The height is less than 5 m or the speed is greater than 35 m/s.
%
% 4.4-21. Create and plot a MATLAB function called f(x, y) to evaluate the function f(x, y) defined as follows:
% f(x,y) = xy \quad if \quad x\ge 0 \quad and \quad y \ge 0 \\
%  \quad \quad  \quad \quad  xy^2 \quad if \quad x\ge 0 \quad and \quad  y \ge 0 \\
% \quad \quad  \quad \quad x^2y \quad if \quad  x<0 \quad and \quad y\ge 0 \\
% \quad \quad  \quad \quad x^2y^2 \quad if \quad x<0 \quad and \quad y<0
%
% Test your function for all four cases.