%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% statement_practice.m
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




%% Question 01
% Evaluate the following expressions without using MATLAB. Check the answer with MATLAB.
% a) 14>15/3
% b) y = 8/2<5x3+1>9
% c) y = 8/(2<5)x3+(1>9)
% d) 2+4*3 ~= 60/4^1



%% Question 02
% Given: a = 4, b = 7. Evaluate the following expressions without using MATLAB. Check the answer with MATLAB.
% a) y = a+b>= a*b 
% b) y= a+(b>=a)*b
% c) y = b-a<a<a/b

%% Question 03
% A vector is given by: x = [15 -6 0 8 -2 5 4 -10 0.5 3]. 
% Using conditional statements and loops, write a program 
% that determines and displays the sum of the positive elements of the vector, 
% and the sum of the negative elements of the vector.

x = [15 -6 0 8 -2 5 4 -10 0.5 3];
positiveSum = 0;
negativeSum = 0;

for i = x 
   if i >= 0
       positiveSum = positiveSum +i;
   else
       negativeSum = negativeSum +i;
   end

end

fprintf('positive sum = %f\n', positiveSum)
fprintf('negative sum = %f\n', negativeSum)


%% Question 04
% Write a MATLAB if statement to calculate f(x)
% The value of f(x) is -2x when x < 0; x(x-2) when x is in [0, 2] and log(x-1) otherwise. 

x = -1

if x < 0
    fx = -2*x;
elseif (x>=0) && (x<=2)
    fx = x(x-2);
else
    fx = log(x-1);
end

fprintf('f(x) = %0.2f\n', fx)


%% Question 05
% Write a program in a script file that finds the smallest even integer that is also divisible by 7 
% and whose cube is greater than 40,000. 
% Use a loop in the program. The loop should start from 1 and stop when the number is found. 
% The program prints a message: ?
% The required number is: ?
% and then prints the number.

for a = 1:1:100
    if (rem(a, 7) == 0) && (a^3>40000);
        fprintf('smallest integer is %d\n', a) 
      if(size(a)==1)
        break;
      end   
    end
    
end


% hint: assume a is an integer, a/7,
% dimension of the cube = length x width x height; a^3 > 40,000
% use fprintf

%% Question 06
% Write a function 'runsum = sum_1_to_n(n)' return the sum of integers from 1 to n
% save a script

% hint: use for end
% hint: set runsum = 0 before the loop

runsum = 0;
for i = 1: 20
    runsum = runsum + i;
end
fprintf('runsum = %d\n', runsum)    


%% Question 07
% Calculates the overall sum of the elements
% hint: two loops (for, for)
% use following commands



mat = [3:5; 2 5 7];
[row col] = size(mat);
% i= row
% j = col

outsum = 0;
for i = 1:row
    for j = 1:col
       outsum = outsum + mat(i,j);
    end 
end


%% Question 08
% Write a script that will prompt the user for a temperature in degree
% Celsius, and then an F for Fahrenheit or K for Kelvin
% The script will print the corresponding temperature in the scale specified by the user. 
% For example, the output might look like this:
% Enter the temp in degrees C: 29.3
% Do you want F or K? F
% The temp in degrees F is 84.7

% The format of the output should be exactly as specified here. The conversions are:
% F = 9/5*C+32
% K = C +273.15

% hint: switch









