matlab Problem 1: from 1934 and ending at 2098. starting from 1933 and ending at
ID: 3595788 • Letter: M
Question
matlab Problem 1: from 1934 and ending at 2098. starting from 1933 and ending at 2099 plc. a) Using colon operator, create a row vector pla containing even integer numbers starting b) Using function linspace, create a row vector plb containing odd integer numbers c) Concatenate the vectors created in parts (a) and b) and put the answer in vector d) What is the length of the vector in part (c) ? Put the answer to pld e) Which element of the vector in part (c) is the number 2052? Use function find. Put the answer to ple. f) Add the number 2100 to the end of the vector in part (c) to create vector plf g) Write an expression that would store the first half of the vector in part (f) in vector plg. h) Write an expression that would store the second half of the vector in part (f) in vector plh i) Create a column vector pli with all odd numbers from 1 to 1235. j) Square all of the elements of the vector in part (i) and put the answer in plj k) Sum all elements of the vector in part (i) and put the answer in plk. l) Find the product of the last eight elements of the vector in part (i) and put the answer in pll m) Find the cumulative sum of the vector in part (i). Put the answer in plm. Problem 2: (a) Create the following matrix and put the answer in p2a. Use MATLAB built-in functions discussed in class. 10 0 011 00 0 1 0 1 01 0 010 1 0 0010 0 0 01 0 0 0 1 0 1 0 0 1 0 1 0 1 0 001 1 0 0 0 1 10 0 01 1 0 0 0 1 0 1 0 1 0 0 1 0 1 0 001 0 0 0 010 0 0 1 01 0 0 1 0 1 0 1 0 0 01 1 0 0 0 1Explanation / Answer
*******************************************************************************
According to Chegg guidelines, posting multiple questions is not allowed.
I have answered 4 parts of the question as per the guidelines.
Explanation:
The only thing that needs explanation is the linspace function but I am
explaining everything.
1.The colon operator is used to generate values here: (1934:2:2098) means the
values start from 1934 to 2098 with a step value 2 so we get even numbers.
2.The linspace function linspace(x1,x2,n) generates equally spaced integers from x1 to x2 with spacing of
(x2-x1)/(n-1)
we need a spacing of 2,
so we solve for n,
(x2-x1)/(n-1)=2
x1=1933,x2=2099
Solving we get n=84
3.horzcat(p1a, p1b) concatenates the vectors
4.length function finds the length of vector
Kindly find the code below.
The outputs have also been provided.
*******************************************************************************
*******************************************************************************
Code:
printf('p1a is row vector ');
p1a=(1934:2:2098)
printf('p1b is row vector ');
p1b= linspace(1933,2099,84)
printf('p1c is concatenated row vector ');
p1c = horzcat(p1a, p1b)
printf('length p1c is stored in p1d: ');
p1d=length(p1c)
*******************************************************************************
*******************************************************************************
Sample Input/Output:
p1a is row vector
p1a =
Columns 1 through 11:
1934 1936 1938 1940 1942 1944 1946 1948 1950 1952 1954
Columns 12 through 22:
1956 1958 1960 1962 1964 1966 1968 1970 1972 1974 1976
Columns 23 through 33:
1978 1980 1982 1984 1986 1988 1990 1992 1994 1996 1998
Columns 34 through 44:
2000 2002 2004 2006 2008 2010 2012 2014 2016 2018 2020
Columns 45 through 55:
2022 2024 2026 2028 2030 2032 2034 2036 2038 2040 2042
Columns 56 through 66:
2044 2046 2048 2050 2052 2054 2056 2058 2060 2062 2064
Columns 67 through 77:
2066 2068 2070 2072 2074 2076 2078 2080 2082 2084 2086
Columns 78 through 83:
2088 2090 2092 2094 2096 2098
p1b is row vector
p1b =
Columns 1 through 11:
1933 1935 1937 1939 1941 1943 1945 1947 1949 1951 1953
Columns 12 through 22:
1955 1957 1959 1961 1963 1965 1967 1969 1971 1973 1975
Columns 23 through 33:
1977 1979 1981 1983 1985 1987 1989 1991 1993 1995 1997
Columns 34 through 44:
1999 2001 2003 2005 2007 2009 2011 2013 2015 2017 2019
Columns 45 through 55:
2021 2023 2025 2027 2029 2031 2033 2035 2037 2039 2041
Columns 56 through 66:
2043 2045 2047 2049 2051 2053 2055 2057 2059 2061 2063
Columns 67 through 77:
2065 2067 2069 2071 2073 2075 2077 2079 2081 2083 2085
Columns 78 through 84:
2087 2089 2091 2093 2095 2097 2099
p1c is concatenated row vector
p1c =
Columns 1 through 11:
1934 1936 1938 1940 1942 1944 1946 1948 1950 1952 1954
Columns 12 through 22:
1956 1958 1960 1962 1964 1966 1968 1970 1972 1974 1976
Columns 23 through 33:
1978 1980 1982 1984 1986 1988 1990 1992 1994 1996 1998
Columns 34 through 44:
2000 2002 2004 2006 2008 2010 2012 2014 2016 2018 2020
Columns 45 through 55:
2022 2024 2026 2028 2030 2032 2034 2036 2038 2040 2042
Columns 56 through 66:
2044 2046 2048 2050 2052 2054 2056 2058 2060 2062 2064
Columns 67 through 77:
2066 2068 2070 2072 2074 2076 2078 2080 2082 2084 2086
Columns 78 through 88:
2088 2090 2092 2094 2096 2098 1933 1935 1937 1939 1941
Columns 89 through 99:
1943 1945 1947 1949 1951 1953 1955 1957 1959 1961 1963
Columns 100 through 110:
1965 1967 1969 1971 1973 1975 1977 1979 1981 1983 1985
Columns 111 through 121:
1987 1989 1991 1993 1995 1997 1999 2001 2003 2005 2007
Columns 122 through 132:
2009 2011 2013 2015 2017 2019 2021 2023 2025 2027 2029
Columns 133 through 143:
2031 2033 2035 2037 2039 2041 2043 2045 2047 2049 2051
Columns 144 through 154:
2053 2055 2057 2059 2061 2063 2065 2067 2069 2071 2073
Columns 155 through 165:
2075 2077 2079 2081 2083 2085 2087 2089 2091 2093 2095
Columns 166 and 167:
2097 2099
length p1c is stored in p1d:
p1d = 167
*******************************************************************************
*******************************************************************************
I hope this helps you.
If you find my answer helpful,
Kindly rate the answer.
All the best :)
*******************************************************************************
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.