목록Solution/MATLAB (13)
개발자 뺚
Generate F = [M1 M^2 ... M^p] with M a matrix, without using for. function F = powerConcat(M,p) F = M; for i = 2:p F = cat(2, F, M^i); end end
If an equilateral triangle has area A, then what is the length of each of its sides, x? Image courtesy of Wikipedia. function x = side_length(A) x = sqrt(2 * A / sin(pi / 3)) end
Write a function that takes N as the input, and outputs a matrix whose upper-left (NxN) quadrant contains all ones, the lower-right (NxN) quadrant contains all N's, and zeros everywhere else. For example, if N = 3: function M = foursquare(N) M = zeros(2 * N); M(1:N, 1:N) = ones(N); M(N + 1:2 * N, N + 1:2 * N) = N * ones(N); end
Network computers have generally a nickname to be identified. Can you guess the nickname of the Cody Computer? No input argument required. Output is a string , for example 'Saturn' or 'Eole' ... function y = your_fcn_name y = getenv('HOSTNAME'); end
Example: If a system of linear equations in x₁ and x₂ is: 2x₁ + x₂ = 2 x₁ - 4 x₂ = 3 Then the coefficient matrix (A) is: 2 1 1 -4 And the constant vector (b) is: 2 3 To solve this system, use mldivide ( \ ): x = A\b Problem: Given a constant input angle θ (theta) in radians, create the coefficient matrix (A) and constant vector (b) to solve the given system of linear equations in x₁ and x₂. cos(..
Given two input vectors: name - user last names age - corresponding age of the person Return the name of the oldest person in the output variable old_name. function old_name = find_max_age(name,age) [value index] = max(age); old_name = name(index); end
If a large number of fair N-sided dice are rolled, the average of the simulated rolls is likely to be close to the mean of 1,2,...N i.e. the expected value of one die. For example, the expected value of a 6-sided die is 3.5. Given N, simulate 1e8 N-sided dice rolls by creating a vector of 1e8 uniformly distributed random integers. Return the difference between the mean of this vector and the mea..
Given an input vector F containing temperature values in Fahrenheit, return an output vector C that contains the values in Celsius using the formula: C = (F–32) * 5/9 function C = temp_convert(F) C = (F - 32) * 5 / 9 end