HW 1: MATLAB


HW 1: MATLAB
Read and execute the commands described Sections 1–10 of Basic Concepts in Matlab
(including creating the function mydist.m) and then answer the following questions (you can 
diary command in Matlab (see help diary) 
to record your commands and results to a text file): 
 1. Given the array x = [3 1 5 7 9 2 6], provide the single command (one line of 
code with at most one assignment (i.e., equals sign =)) needed to perform the following 
actions. Unless noted, all of the actions should not modify x; instead, the result of the 
action will be assigned to the default variable ans. 
 (a) Extract the forth element from x
 (b) Extract all but the last element from x
 (c) Extract the first, third, first, fifth, and first element from x
 (d) Reverse the elements of x
 (e) Calculate the sum of all of the elements of x
 (f) Calculate the sum of the first to the ith element of x, for all elements of x
 (g) Set the second and sixth elements of x equal to zero 
 (h) Modify x by deleting its third element 
 (i) Using the result from (h), modify x by converting it into a 2  3 matrix, where the 
first row of the matrix has the first three elements of x
2
 2. Let x = [6 2 1 4] and A = [2 7 9 7; 3 1 4 6; 8 1 2 5], provide the 
single command needed to: 
 (a) Add x to each row of A
 (b) Add x to the sum of each column of A
 (c) Add the sum of x to each element of A
 (d) Calculate the sum of the element-by-element product of each row of A and x
 3. Given that x = [1 5 2 7 9 0 1] and y = [5 2 2 6 0 0 2], provide the 
single command needed to: 
 (a) Extract from x those values that are greater than the corresponding values of y
 (b) Extract from x those values that are both greater than the corresponding values of y
and less than 6 
 (c) Extract from x those values that are either less than 2 or greater than 6 
 (d) Modify y by adding 1 to each of its nonzero values 
 (e) Divide each element of y by the corresponding element of x as long as the element of 
x is nonzero (to avoid dividing by zero) 
 (f) Modify y by setting all of its zero values to 1 
 4. Modify the Minimum-Distance Location example in Basic Concepts so that it can be used 
to find the location that minimizes the maximum distance traveled between x and the three 
points in P. 
 5. Modify the Minimum-Distance Location example in Basic Concepts so that it can be used 
to find the location that minimizes the sum of distance traveled assuming that 3, 2, and 4 
trips, respectively, are made between x and the three points in P. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值