Homework 1: Due Midnight on Tuesday October 6th

1) Create the following vectors using both linspace and the ':' technique:

a) [1 2 3 4 5 6 7 8 9 10]

b) [10 8 6 4 2 0 -2 -4]

c) [0 3.1416 6.2832 9.4248 12.5664 15.7080]

 

2) Start with the following string:

str = 'aaaaaaaaaaaaaaaaaaaa';

a) Make every third letter in the string 'c'

b) Then use indexing to turn the string into: 'abcabcabcabcabcabcab'

c) Now use indexing to turn the string into: 'abcdefabcabcabcabcab'

d) Finally, use indexing to turn the string into: 'abcdefabcdefabcdefab'

e) Demonstrate that the 6th, 12th and 18th letters in the string are f's

_________-

Here's an example of text for an m-file containing a complete answer to an example homework question (taken from the course lessons at the end of chapter 2)

%Geoff Boynton, Psych 538B
%Homework 1, Example problem
%
%Create the following vector using both linspace and the : technique
%
%x1= [4.0000 7.5000 11.0000 14.5000 18.0000 21.5000 25.0000 28.5000 32.0000 35.5000 39.0000]

%linspace technique:
x1= linspace(4,39,11)

%colon technique:
x1=4:3.5:40

%x2 = [40.0000 37.5000 35.0000 32.5000 30.0000 27.5000 25.0000
% 22.5000 20.0000 17.5000 15.0000 12.5000 10.0000 7.5000
% 5.0000 2.5000 0 -2.5000]

%linspace technique:
x2 = linspace(40,-2.5,18)

%colon technique:
x2 = 40:-2.5:-2.5