목록Solution/MATLAB (13)
개발자 뺚
Return 1 if the input is sorted from highest to lowest, 0 if not. Example: 1:7 -> 0 [7 5 2] -> 1 function y = your_fcn_name(x) des_x = sort(x, 'descend') if isequal(x, des_x) y = 1 else y = 0 end end
Given two input variables r and h, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top). Return the result in output variable SA. function SA = func_frosting(r,h) SA = pi * r ^ 2 + 2 * pi * r * h; end
Given two lists of numbers, determine the weighted average as follows Example [1 2 3] and [10 15 20] should result in 33.3333 (1*10 + 2*15 + 3*20)/3 function y = weighted_average(x,w) [row, col] = size(x); sum = 0; for i = 1:col sum = sum + x(i) * w(i); end y = sum / col; end
Assuming a simple diatonic C scale, calculate the interval (integer) between two notes (provided as strings). By applying numbers to the notes of the scale (C,D,E,F,G,A,B,C = 1,2,3,4,5,6,7,8), intervals can be calculated. Because a unison is defined as one rather than zero, you add one to the numerical difference. The intervals are defined as: C - C: perfect unison, 1 C - D: major second, 2 C - ..