Assignment Chef icon Assignment Chef

Browse assignments

Assignment catalog

33,401 assignments available

[SOLVED] 16-720b computer vision: homework 1 spatial pyramid matching for scene classification

Overview The bag-of-words (BoW) approach, which you learned about in class, has been applied to a myriad of recognition problems in computer vision. For example, two classic ones are object recognition [5, 7] and scene classification [6, 8]1 . Beyond that, the BoW representation has also been the subject of a great deal of study aimed at improving it, and you will see a large number of approaches that remain in the spirit of bag-of-words but improve upon the traditional approach which you will implement here. For example, two important extensions are pyramid matching [2, 4] and feature encoding [1]. An illustrative overview of the homework is shown in Figure. 2. In Section. 1, we will build the visual words from the training set images. With the visual words, i.e. the dictionary, in Section. 2 we will represent an image as a visual-word vector. Then the comparison between images is realized in the visual-word vector space. Finally, we will build a scene recognition system based on the visual bag-of-words approach to classify a given image into 8 types of scenes. ….. …… …… Feature extraction Cluster Visual word vocabulary …… …… Visual word vocabulary Feature extraction Feature extraction Image represented as histogram of visual-words Building the dictionary Represent images as histograms of visual words and compare images Compare Figure 2: An overview of the bags-of-words approach to be implemented in the homework. Given the training set of images, the visual features of the images are extracted. In our case, we will use the filter responses of the pre-defined filter bank as the visual features. The visual words, i.e. dictionary, are built as the centers of clusterings of the visual features. During recognition, the image is first represented as a vector of visual words. Then the comparison between images is realized in the visual-word vector space. Finally, we will build a scene recognition system that classifies the given image into 8 types of scenes What you will be doing: You will implement a scene classification system that uses the bag-of-words approach with its spatial pyramid extension. The paper that introduced the pyramid matching kernel [2] is: K. Grauman and T. Darrell. The Pyramid Match Kernel: Discriminative Classification with Sets of Image Features. ICCV 2005. http://www.cs.utexas.edu/ ~grauman/papers/grauman_darrell_iccv2005.pdf Spatial pyramid matching [4] is presented at: 1This homework aims at being largely self-contained; however, reading the listed papers (even without trying to truly understand them) is likely to be helpful. 2 Figure 3: The provided multi-scale filter bank S. Lazebnik, C. Schmid, and J. Ponce, Beyond Bags of Features: Spatial Pyramid Matching for Recognizing Natural Scene Categories, CVPR 2006. http://www.di. ens.fr/willow/pdfs/cvpr06b.pdf You will be working with a subset of the SUN database2 . The data set contains 1600 images from various scene categories like “auditorium”, “desert” and “kitchen”. And to build a recognition system, you will: • first, take responses of a filter bank on images and build a dictionary of visual words; • then, learn a model for the visual world based on the bag of visual words (with spatial pyramid matching [4]), and use nearest-neighbor to predict scene classes in a test set. In terms of number of lines of code, this assignment is fairly small. However, it may take a few hours to finish running the baseline system, so make sure you start early so that you have time to debug things. Also, try each component on a subset of the data set first before putting everything together. We provide you with a number of functions and scripts in the hopes of alleviating some tedious or error-prone sections of the implementation. You can find a list of files provided in Section 4. Notice that, we include num workers as input for some functions you need to implement. Those are not necessary, but can be used with multi-threading python libraries to significantly speed up your code. This homework was tested using python3.5 and pytorch 0.4.1. 1 Representing the World with Visual Words 1.1 Extracting Filter Responses We want to run a filter bank on an image by convolving each filter in the bank with the image and concatenating all the responses into a vector for each pixel. In our case, we will be using 20 filters consisting of 4 types of filters in 5 scales. The filters are: (1) Gaussian, (2) Laplacian of Gaussian, (3) derivative of Gaussian in the x direction, and (4) derivative of Gaussian in the y direction. The convolution function scipy.ndimage.convolve() can be used with user-defined filters, but the functions scipy.ndimage.gaussian filter() and scipy.ndimage.gaussian laplace() may be useful here for improved efficiency. The 5 scales we will be using are 1, 2, 4, 8, and 8√ 2, in pixel units. Q1.1.1 (5 points): What properties do each of the filter functions (See Figure 3) pick up? You should group the filters into broad categories (e.g. all the Gaussians). Also, why do we need multiple scales of filter responses? Answer in your write-up. 2http://groups.csail.mit.edu/vision/SUN/ 3 Figure 4: An input image and filter responses for all of the filters in the filter bank. (a) The input image (b) The filter responses of Lab image corresponding to the filters in Figure. 3 Q1.1.2 (10 points): For the code, loop through the filters and the scales to extract responses. Since color images have 3 channels, you are going to have a total of 3F filter responses per pixel if the filter bank is of size F. Note that in the given dataset, there are some gray-scale images. For those gray-scale images, you can simply duplicated them into three channels using the command repmat. Then output the result as a 3F channel image. Complete the function visual words.extract filter responses(image) and return the responses as filter responses. We have provided you with a template code with detailed instructions in it. You would be required to input a 3-channel RGB or gray-scale image and filter bank to get the responses of the filters on the image. Remember to check the input argument image to make sure it is a floating point type with range 0 1, and convert it if necessary. Be sure to check the number of input image channels and convert it to 3-channel if it is not. Before applying the filters, use the function skimage.color.rgb2lab() to convert your image into the Lab color space, which was designed to more effectively quantify color differences with respect to human perception. (See here for more information.) If image is an M × N × 3 matrix, then filter responses should be a matrix of size M × N × 3F. Make sure your convolution function call handles image padding along the edges sensibly. Apply all 20 filters on a sample image, and visualize as a image collage (as shown in Figure 4). You can use the included helper function util.display filter responses() (which expects a list of filter responses with those of the Lab channels grouped together with shape M × N × 3) to create the collage. Submit the 4 collage of 20 images in the write-up. 1.2 Creating Visual Words You will now create a dictionary of visual words from the filter responses using k-means. After applying k-means, similar filter responses will be represented by the same visual word. You will use a dictionary with fixed-size. Instead of using all of the filter responses (that can exceed the memory capacity of your computer), you will use responses at α random pixels3 . If there are T training images, then you should collect a matrix filter responses over all the images that is αT × 3F, where F is the filter bank size. Then, to generate a visual words dictionary with K words, you will cluster the responses with k-means using the function sklearn.cluster.KMeans as follows: kmeans = sklearn.cluster.KMeans(n clusters=K).fit(filter responses) dictionary = kmeans.cluster centers You can alternatively pass the n jobs argument into the KMeans() object to utilize parallel computation. Q1.2 (10 points): You should write the functions visual words.compute dictionary one image(args) visual words.compute dictionary() to generate a dictionary given a list of images. The overall goal of compute dictionary() is to load the training data, iterate through the paths to the image files to read the images, and extract αT filter responses over the training files, and call k-means. This can be slow to run; however, the images can be processed independently and in parallel. Inside compute dictionary one image(), you should read an image, extract the responses, and save to a temporary file. Here, args is a collection of arguments passed into the function. Inside compute dictionary(), you should load all the training data and create subprocesses to call compute dictionary one image(). After all the subprocesses are finished, load the temporary files back, collect the filter responses, and run k-means. A sensible initial value to try for K is between 100 and 300, and for α is between 50 and 500, but they depend on your system configuration and you might want to play with these values. Finally, execute compute dictionary() and go get a coffee. If all goes well, you will have a file named dictionary.npy that contains the dictionary of visual words. If the clustering takes too long, reduce the number of clusters and samples. If you have debugging issues, try passing in a small number of training files manually. 1.3 Computing Visual Words Q1.3 (10 points): We want to map each pixel in the image to its closest word in the dictionary. Complete the following function to do this: visual words.get visual words(image,dictionary) and return wordmap, a matrix with the same width and height as image, where each pixel in wordmap is assigned the closest visual word of the filter response at the respective pixel in image. We will use the standard Euclidean distance to do this; to do this efficiently, use the function scipy.spatial.distance.cdist(). Some sample results are shown in Fig. 5. Visualize three wordmaps of three images from any one of the category and submit in the write-up along with their original RGB image. Also, provide your comments about the visualization. They should look similar to the ones in Figure 5. 3Try using numpy.random.permutation(). 5 Figure 5: Visual words over images. You will use the spatially un-ordered distribution of visual words in a region (a bag of visual words) as a feature for scene classification, with some coarse information provided by spatial pyramid matching [4] 2 Building a Recognition System We have formed a convenient representation for recognition. We will now produce a basic recognition system with spatial pyramid matching. The goal of the system is presented in Fig. 1: given an image, classify (colloquially, “name”) the scene where the image was taken. Traditional classification problems follow two phases: training and testing. During training time, the computer is given a pile of formatted data (i.e., a collection of feature vectors) with corresponding labels (e.g., “desert”, “kitchen”) and then builds a model of how the data relates to the labels: “if green, then kitchen”. At test time, the computer takes features and uses these rules to infer the label: e.g., “this is green, so therefore it is kitchen”. In this assignment, we will use the simplest classification model: nearest neighbor. At test time, we will simply look at the query’s nearest neighbor in the training set and transfer that label. In this example, you will be looking at the query image and looking up its nearest neighbor in a collection of training images whose labels are already known. This approach works surprisingly well given a huge amount of data, e.g., a very cool graphics applications from [3]. The components of any nearest-neighbor system are: features (how do you represent your instances?) and similarity (how do you compare instances in the feature space?). You will implement both. 2.1 Extracting Features We will first represent an image with a bag of words approach. In each image, we simply look at how often each word appears. Q2.1 (10 points): Write the function visual recog.get feature from wordmap(wordmap,dict size) that extracts the histogram4 of visual words within the given image (i.e., the bag of visual words). As inputs, the function will take: • wordmap is a H × W image containing the IDs of the visual words • dict size is the maximum visual word ID (i.e., the number of visual words, the dictionary size). Notice that your histogram should have dict size bins, corresponding to how often that each word occurs. 4Look into numpy.histogram() 6 As output, the function will return hist, a dict size histogram that is L1 normalized, (i.e., the sum equals 1). You may wish to load a single visual word map, visualize it, and verify that your function is working correctly before proceeding. 2.2 Multi-resolution: Spatial Pyramid Matching Bag of words is simple and efficient, but it discards information about the spatial structure of the image and this information is often valuable. One way to alleviate this issue is to use spatial pyramid matching [4]. The general idea is to divide the image into a small number of cells, and concatenate the histogram of each of these cells to the histogram of the original image, with a suitable weight. Here we will implement a popular scheme that chops the image into 2l × 2 l cells where l is the layer number. We treat each cell as a small image and count how often each visual word appears. This results in a histogram for every single cell in every layer. Finally to represent the entire image, we concatenate all the histograms together after normalization by the total number of features in the image. If there are L + 1 layers and K visual words, the resulting vector has dimensionality K PL l=0 4 l = K 4 (L+1) − 1  /3. Now comes the weighting scheme. Note that when concatenating all the histograms, histograms from different levels are assigned different weights. Typically (in [4]), a histogram from layer l gets half the weight of a histogram from layer l + 1, with the exception of layer 0, which is assigned a weight equal to layer 1. A popular choice is for layer 0 and layer 1 the weight is set to 2−L, and for the rest it is set to 2l−L−1 (e.g., in a three layer spatial pyramid, L = 2 and weights are set to 1/4, 1/4 and 1/2 for layer 0, 1 and 2 respectively, see Fig. 6). Note that the L1 norm (absolute values of all dimensions summed up together) for the final vector is 1. Figure 6: Spatial Pyramid Matching: From [4]. Toy example of a pyramid for L = 2. The image has three visual words, indicated by circles, diamonds, and crosses. We subdivide the image at three different levels of resolution. For each level of resolution and each channel, we count the features that fall in each spatial bin. Finally, weight each spatial histogram. Q2.2 (15 points): Create a function getImageFeaturesSPM that form a multi-resolution representation of the given image. visual recog.get feature from wordmap SPM(wordmap,layer num,dict size) As inputs, the function will take: • layer num the number of layers in the spatial pyramid, i.e., L + 1 • wordmap is a H × W image containing the IDs of the visual words • dict size is the maximum visual word ID (i.e., the number of visual words, the dictionary size) As output, the function will return hist all, a vector that is L1 normalized. Please use a 3-layer spatial pyramid (L = 2) for all the following recognition tasks. One small hint for efficiency: a lot of computation can be saved if you first compute the histograms of the finest layer, because the histograms of coarser layers can then be aggregated from finer ones. Make sure you normalize the histogram after aggregation. 2.3 Comparing images We will also need a way of comparing images to find the “nearest” instance in the training data. In this assignment, we’ll use the histogram intersection similarity. The histogram intersection similarity between two histograms is the sum of the minimum value of each corresponding bins. Note that since this is a similarity, you want the largest value to find the “nearest” instance. Q2.3 (10 points): Create the function visual recog.distance to set(word hist,histograms) where word hist is a K 4 (L+1) − 1  /3 vector and histograms is a T ×K 4 (L+1) − 1  /3 matrix containing T features from T training samples concatenated along the rows. This function returns the histogram intersection similarity between word hist and each training sample as a vector of length T. Since this is called every time you want to look up a classification, you want this to be fast, so doing a for-loop over tens of thousands of histograms is a very bad idea. 2.4 Building A Model of the Visual World Now that we’ve obtained a representation for each image, and defined a similarity measure to compare two spatial pyramids, we want to put everything up to now together. You will need to load the training file names from data/train data.npz and the filter bank and visual word dictionary from dictionary.npy. You will save everything to a .npz file named trained system.npz. Included will be: 1. dictionary: your visual word dictionary. 2. features: a N × K 4 (L+1) − 1  /3 matrix containing all of the histograms of the N training images in the data set. A dictionary with 150 words will make a train features matrix of size 1440 × 3150. 3. labels: an N vector containing the labels of each of the images. (features[i] will correspond to label labels[i]). 4. SPM layer num: the number of spatial pyramid layers you used to extract the features for the training images. We have provided you with the names of the training images in data/train data.npz. You want to use the dictionary entry image names for training. You are also provided the names of the test images in data/test data.npz, which is structured in the same way as the training data; however, you cannot use the testing images for training. If it’s any helpful, the below table lists the class names that correspond to the label indices: 0 1 2 3 4 5 6 7 auditorium baseball field desert highway kitchen laundromat waterfall windmill Q2.4 (15 points): Implement the function visual recog.build recognition system() that produces trained system.npz. You may include any helper functions you write in visual recog.py. Implement visual recog.get image feature(file path,dictionary,layer num,K) that load image, extract word map from the image, compute SPM feature and return the computed feature. Use this function in your visual recog.build recognition system(). 2.5 Quantitative Evaluation Qualitative evaluation is all well and good (and very important for diagnosing performance gains and losses), but we want some hard numbers. Load the corresponding test images and their labels, and compute the predicted labels of each, i.e., compute its distance to every image in training set and return the label with least distance difference as the predicted label. To quantify the accuracy, you will compute a confusion matrix C: given a classification problem, the entry C(i,j) of a confusion matrix counts the number of instances of class i that were predicted as class j. When things are going well, the elements on the diagonal of C are large, and the off-diagonal elements are small. Since there are 8 classes, C will be 8 × 8. The accuracy, or percent of correctly classified images, is given by the trace of C divided by the sum of C. Q2.5 (10 points): Implement the function visual recog.evaluate recognition system() that tests the system and outputs the confusion matrix. Report the confusion matrix and accuracy for your results in your write-up. This does not have to be formatted prettily: if you are using LATEX, you can simply copy/paste it into a verbatim environment. Additionally, do not worry if your accuracy is low: with 8 classes, chance is 12.5%. To give you a more sensible number, a reference implementation with spatial pyramid matching gives an overall accuracy of around 50%. 2.6 Find the failed cases There are some classes/samples that are more difficult to classify than the rest using the bags-of-words approach. As a result, they are classified incorrectly into other categories. Q2.6 (5 points): List some of these classes/samples and discuss why they are more difficult in your write-up. 3 Deep Learning Features – An Alternative to “Bag of Words” As we have discussed in class, another powerful method for scene classification in computer vision is the employment of convolutional neural networks (CNNs) – sometimes referred to generically as “deep learning”. It is important to understand how previously trained (pretrained) networks can be used as another form of feature extraction, and how they relate to classical Bag of Words (BoW) features. We will be covering details on how one chooses the network architecture and training procedures later in the course. For this question, however, we will be asking you to deal with the VGG-16 pretrained network. VGG-16 is a pretrained Convolutional Neural Network (CNN) that has been trained on approximately 1.2 million images from the ImageNet Dataset (http://image-net.org/index) by the Visual Geometry Group (VGG) at University of Oxford. The model can classify images into a 1000 object categories (e.g. keyboard, mouse, coffee mug, pencil). or later installed. One lesson we want you to take away from this exercise is to understand the effectiveness of “deep features” for general classification tasks within computer vision – even when those features have been previously trained on a different dataset (i.e. ImageNet) and task (i.e. object recognition). 3.1 Extracting Deep Features To complete this question, you need to install the torchvision library from Pytorch, a popular Pythonbased deep learning library. If you are using the Anaconda package manager (https://www.anaconda.com/ download/), this can be done with the following command: conda install pytorch torchvision -c pytorch To check that you have installed it correctly, make sure that you can import torch in a Python interpreter without errors. Please refer to https://pytorch.org/ for more detailed installation instructions. 9 Q3.1 (25 points): We want to extract out deep features corresponding to the convolutional layers of the VGG-16 network. To load the network, add the line vgg16 = torchvision.models.vgg16(pretrained=True).double() followed by vgg16.eval() The latter line ensures that the VGG-16 network is in evaluation mode, not training mode. We want you to complete a function that is able to output VGG-16 network outputs at the fc7 layer in network layers.py. network layers.extract deep feature(x,vgg16 weights) where x refers to the input image and vgg16 weights is a structure containing the CNN’s network parameters. In this function you will need to write sub-functions multichannel conv2d, relu, max pool2d, and linear corresponding to the fundamental elements of the CNN: multi-channel convolution, rectified linear units (ReLU), max pooling, and fully-connected weighting. We have provided a helper function util.get VGG16 weights() that extracts the weight parameters of VGG-16 and its meta information. The returned variable is a numpy array of shape L × 3, where L is the number of layers in VGG-16. The first column of each row is a string indicating the layer type. The second/third columns may contain the learned weights and biases, or other meta-information (e.g. kernel size of max-pooling). Please refer to the function docstring for details. VGG-16 assumes that all input imagery to the network is resized to 224×224 with the three color channels preserved (use skimage.transform.resize() to do this before passing any imagery to the network). And be sure to normalize the image using suggested mean and std before extracting the feature: mean=[0.485,0.456,0.406] std=[0.229,0.224,0.225] In order to build the extract deep feature function, you should run a for-loop through each layer index until layer “fc7”, which corresponds to the second linear layer (Refer to VGG structure to see where “fc7” is). Remember: the output of the preceding layer should be passed through as an input to the next. Details on the sub-functions needed for the extract deep feature function can be found below. Please use scipy.ndimage.convolve and numpy functions to implement these functions instead of using pytorch. Please keep speed in mind when implementing your function, for example, using double for loop over pixels is not a good idea. 1. multichannel conv2d(x,weight,bias): a function that will perform multi-channel 2D convolution which can be defined as follows, y (j) = X K k=1 x (k) ∗ h (j,k) + b[j] (1) where ∗ denotes 2D convolution, x = {x (k)} K k=1 is our vectorized K-channel input signal, h = {h (j,k)} K,J k=1,j=1 is our J × K set of vectorized convolutional filters and r = {y (j)} J j=1 is our J channel vectorized output response. Further, unlike traditional single-channel convolution CNNs often append a bias vector b whose J elements are added to the J channels of the output response. To implement multichannel conv2d, use the Scipy convolution function scipy.ndimage.convolve() with for loops to cycle through the filters and channels. All the necessary details concerning the number of filters (J), number of channels (K), filter weights (h) and biases (b) can be inferred from the shapes/dimensions of the weights and biases. 10 2. relu(x): a function that shall perform the Rectified Linear Unit (ReLU) which can be defined mathematically as, ReLU(x) = max x (x, 0) (2) and is applied independently to each element of the matrix/vector x passed to it. 3. max pool2d(x,size): a function that shall perform max pooling over x using a receptive field of size size × size (we assume a square receptive field here for simplicity). If the function receives a multi-channel input, then it should apply the max pooling operation across each input channel independently. (Hint: making use of smart array indexing can drastically speed up the code.) 4. linear(x,W,b): a function that will compute a node vector where each element is a linear combination of the input nodes, written as y[j] = X K k=1 W[j, k]x[k] + b[j] (3) or more succinctly in vector form as y = Wx + b – where x is the (K × 1) input node vector, W is the (J × K) weight matrix, b is the (J × 1) bias vector and y is the (J × 1) output node vector. You should not need for-loops to implement this function. For efficiency you should check that each sub-function is working properly before putting them all together – otherwise it will be hard to track any errors. You can check the performance of each layer by creating your own single-layer network. 3.2 Building a Visual Recognition System: Revisited We want to compare how useful deep features are in a visual recognition system. Q3.2 (5 points): Implement the functions deep recog.build recognition system(vgg16) and deep recog.eval recognition system(vgg16) both of which takes the pretrained VGG-16 network as the input arguments. These functions should follow a very similar pipeline to those in the previous questions, so you are free to reuse much of the code. The former function should produce trained system deep.npz as the output. Included will be: 1. features: a N × K matrix containing all the deep features of the N training images in the data set. 2. labels: an N vector containing the labels of each of the images. (features[i] will correspond to label labels[i]). The latter function should produce the confusion matrix, as with the previous question. Instead of using the histogram intersection similarity, write a function to just use the negative Euclidean distance (as larger values are more similar). Report the confusion matrix and accuracy for your results in your write-up. Can you comment in your writeup on whether the results are better or worse than classical BoW – why do you think that is? 4 HW1 Distribution Checklist After unpacking hw1.zip, you should have a folder hw1 containing one folder for the data (data) and one for your code (code). In the code folder, where you will primarily work, you will find: • visual words.py: function definitions for extracting visual words. • visual recog.py: function definitions for building a visual recognition system. 11 • network layers.py: function definitions for implementing deep network layers. • deep recog.py: function definitions for building a visual recognition system using deep features. • util.py: utility functions • main.py: main function for running the system The data folder contains: • data/: a directory containing .jpg images from SUN database. • data/train data.npz: a .npz file containing the training set. • data/test data.npz: a .npz file containing the test set. • data/vgg16 list.npy: a .npy file with the weights of VGG-16. 5 HW1 Submission Checklist The assignment should be submitted to Canvas. The writeup should be submitted as a pdf file named hw1.pdf. The code should be submitted as a zip file named .zip. By extracting the zip file, it should have the following files in the structure defined below. (Note: Missing to follow the structure will incur huge penalty in scores). When you submit, remove the folder data/, as well as any large temporary files that we did not ask you to create. • / # A directory inside .zip file – code/ ∗ dictionary.npy ∗ trained system.npz ∗ – hw1.pdf make sure you upload this pdf file to Gradescope. Please assign the locations of answers to each question on Gradescope. References [1] K. Chatfield, V. Lempitsky, A. Vedaldi, and A. Zisserman. The devil is in the details: an evaluation of recent feature encoding methods. In British Machine Vision Conference, 2011. [2] K. Grauman and T. Darrell. The pyramid match kernel: discriminative classification with sets of image features. In Computer Vision (ICCV), 2005 IEEE International Conference on, volume 2, pages 1458– 1465 Vol. 2, 2005. [3] James Hays and Alexei A Efros. Scene completion using millions of photographs. ACM Transactions on Graphics (SIGGRAPH 2007), 26(3), 2007. [4] S. Lazebnik, C. Schmid, and J. Ponce. Beyond bags of features: Spatial pyramid matching for recognizing natural scene categories. In Computer Vision and Pattern Recognition (CVPR), 2006 IEEE Conference on, volume 2, pages 2169–2178, 2006. [5] D.G. Lowe. Object recognition from local scale-invariant features. In Computer Vision (ICCV), 1999 IEEE International Conference on, volume 2, pages 1150–1157 vol.2, 1999. [6] Laura Walker Renninger and Jitendra Malik. When is scene identification just texture recognition? Vision research, 44(19):2301–2311, 2004. 12 [7] J. Winn, A. Criminisi, and T. Minka. Object categorization by learned universal visual dictionary. In Computer Vision (ICCV), 2005 IEEE International Conference on, volume 2, pages 1800–1807 Vol. 2, 2005. [8] Jianxiong Xiao, J. Hays, K.A. Ehinger, A. Oliva, and A. Torralba. Sun database: Large-scale scene recognition from abbey to zoo. In Computer Vision and Pattern Recognition (CVPR), 2010 IEEE Conference on, pages 3485–3492, 2010. 13

$25.00 View

[SOLVED] Cst8116 assignment 01

Software Development Process, design and create an Object-Oriented Java Program Instructions Any assignment submission which does not include the required .java source code files will receive a maximum grade of 3/20 Any assignment submission which is not object oriented (all input/output/computations are in main and there is no object class for the bacteria calculation) will receive a maximum grade of 6/20 You must use the Java API Math class in your program to compute a value using an exponent. If the Math class is not used: -4 deduction. You must use printf to format the final number of bacteria to 2 decimal places. If printf is not used, -1 deduction. • The Software Development Process by Cay Horstmann [1] will be used as the basis for this lab assignment. 1) Understand the problem 2) Develop and Describe an Algorithm 3) Test Algorithm with Simple Inputs 4) Translate the Algorithm into Java 5) Compile and Test Your Program Learning Resources Week 2 Lecture regarding classes Math, Scanner Week 3 Lecture materials regarding creating a class, with variables, constructors, get & set methods, worker method(s) Hybrid 3 for more on UML Class diagrams, and using the UMLet software. Hybrid 4 for information on using printf to format numeric output. See [1] for more help with Java, and [2] for more help with pseudocode and UML Class Diagrams What is the problem to solve? https://www.algebra.com/algebra/homework/logarithm/Bacteria-growth-problems.lesson You have a petri dish of bacteria with 5 bacteria in it. The bacteria doubles every 15 minutes. Given a particular time, you must estimate how many bacteria there are. • Create an Object-Oriented Java Program that calculates the bacteria in the dish after the entered time in minutes and seconds • The program should output the number of bacteria formatted to 2 decimal places. • Minimally, you will create two classes, one to represent or model a petri dish, and another with a main method. The main method will get user input, create a petri dish object, and make method calls on that object. The class that models the petri dish must perform the estimate of bacteria calculation and returns its value to the main method, which will output the value to the user. Hint: you may want to convert all time to seconds before doing the Bacteria computations. For example, 66 minutes and 3 seconds = 66*60 + 3 = 3963 seconds. 1) Understand the problem • Locate at least one website that details the exponential formula needed to calculate the growth of bacteria other than the one above. Write the formula into your MS Word document, on one line as plain-text, and cite and reference your source in IEEE reference format. • Write a formula that will perform the required calculation. (it must use exponent math ie. 2t ) • Write 3 sample calculations. Ie. How many bacteria are produced after • 5 minutes? • 20 minutes and 30 seconds? • 1 minute? (Tip: See lecture notes week 1 for a document to help with citations and references). 2) Develop and Describe an Algorithm including Classes (MS-Word Document Submission) 2a) UML Class Diagrams • Determine what objects, the properties of the objects, and behaviors would be required for an object-oriented program, start with simple UML class diagrams and as you work out more details document the design with a detailed UML class diagram. • Include your detailed UML Class diagrams in your MS Word document. (See lecture notes week 3). • One class diagram should document field variables, constructor(s), getter(s) and setter(s) and one worker method. • One class diagram should document a class that only contains method main. 2b) Pseudocode and Flowchart (MS-Word Document Submission) • NOTE: You are expected to use at least one method in the Java API Math. class and one field value from the Java API Math class. • Write pseudocode and flowchart for the main method, as well as any worker method(s) that calculate how much bacteria is produced. • Include your pseudocode and flowchart in your MS Word document. • Note: You are not required to write pseudocode or flowcharts for getter(s) or setter(s) or constructor(s) for this assignment, the expectation would be the main method and one worker method. 3) Algorithm Test Table (MS-Word Document Submission) • As per the lecture notes, use a table within your MS Word document to test the algorithm for method main. Consider picking numbers that might be expected as input and work through the algorithm documenting expected outputs, you may use a calculator. • You must have 5 rows! • If there is a problem with the algorithm based on this desk-check (using the test plan) then correct the pseudocode and UML class diagram(s) and repeat this step again. 4) Translate the Algorithm into Java • You are to use the Eclipse IDE to create your Java program, use a project name like Assignment 01. • Don’t forget to comment your code files, with the expected code headers o File-level comments, similar to an assignment cover page. o Class-header comment, just above the class declaration with brief description of the class o Method-header comment(s), just above each method or constructor with brief description o Cite and Reference the web source where you located the formula for the volume of a cone. 5)Program Test Table (MS-Word Document Submission) • Re-create your testing table from step 3 in this section, but document what the program outputs are using valid inputs, do they match expectations? • Test with some invalid inputs, and document what happens. Note that some input will crash your program, this is okay as you may not know how to fix this at this point in the course. Document what the error messages are in your test plan. Suggested invalid tests: enter a String instead of a number, use a negative number as input, use zero as part of the input. Try some things and document what happens. • The test plan for the program must be a separate table in your document, if you provide only one test plan table for both testing the algorithm and testing the program you will not be awarded marks for both. Minimally, this second table must also have each row updated to indicate that it was used to test the program, in other words if you copy and paste an exact copy of your first table unchanged you will not earn full marks. (4 & 5) Java Program Screen Shot • Include a screen shot of your program after it has run, place the screen shot into your MS Word document. • The screen shot should show your full name, as part of the program output in the Eclipse Console Window. • The program should accept inputs, provide outputs, and complete successfully. o Even if the program does not fully work, part marks are available for a screen shot. Microsoft Word Document: Suggested Headings Understand the problem UML Class Diagram(s) Pseudocode Before Test Table After Test Table Screen Shot of Program Execution References Submission Requirements • You will need to submit your MS Word document and your Java source code file(s) • Follow your lab professor’s submission guidelines. • You are not required to copy and paste Java code into the MS Word document, however your .java file(s) must be submitted as Java source code files along side your MS Word document. Grading (22 points) Criteria Missing / Poor (0) Below Expectations (1) Meets Expectations (2) Understand the problem Missing or poorly done. Problem solution statement is partly correct, may not have examples of the calculations required to solve the problem. Problem solution statement is correct. Sample calculations needed to solve the problem are provided. Includes cited and referenced source. Algorithm: UML class diagram Missing or poorly done. Class diagram(s) are not in correct format, properties and methods may not be assigned correctly to the classes and / Class diagram(s) are correct format, properties and methods are assigned to appropriate classes, based on the word problem. or there is only one class that contains all of the program functionality. Algorithm: pseudocode Missing or poorly done. Not in correct format and / or steps are not in an order that produces correct results. Not all worker method(s) and / or method main are documented. Correct format, steps are in order that produces correct results. Worker method(s) and method main are documented. Algorithm: flowcharts Missing or poorly done. Not in correct format and / or steps are not in an order that produces correct results. Not all worker method(s) and / or method main are documented. Correct format, steps are in order that produces correct results. Worker method(s) and method main are documented. Test Plan: Algorithm Missing or poorly done. Does not have correct table format as seen in lecture notes and lab exercises, and / or does not test program using samples of acceptable inputs. Less than 5 rows. Has correct table format as seen in lecture and lab exercises, tests program using samples of acceptable inputs. Test Plan: Program Missing or poorly done or unchanged copy of algorithm test table. Does not have correct table format as seen in lecture notes and lab exercises, and / or does not test program using samples of acceptable inputs and / or does not document program errors resulting from invalid inputs. Less than 5 rows Has correct table format as seen in lecture and lab exercises, tests program using samples of acceptable inputs, and documents program errors resulting from invalid inputs. Source Code: *.java file(s) Comments and Conventions Missing or poorly done. File comment header with student name is present. Class and / or class-member (constructors, methods) are missing comment headers. Loosely follows Java coding conventions for identifiers, indentation. File comment header with student full name is present. Class and / or class-member (constructors, methods) have comment headers. Closely follows Java coding conventions for identifiers, indentation. Source Code: *.java file(s) program structure and logic. Missing or poorly done. Program may have small syntax mistakes or produces incorrect output. Program may consist entirely within method main (is not object-oriented). Program has correct syntax and program logic that produces correct output. Program is objectoriented with classes, fields, get / set methods, worker methods. Running Program *.java file(s) Program Structure and Logic Student files will not compile and run on professor’s computer due to syntax mistakes in the student’s source code. Program compiles and runs; however, program does not work correctly with valid input value(s) as used by lab professor to test program. Program compiles and runs and program does work correctly with valid input value(s) as used by lab professor to test program. Screen Shot of Program Execution in Eclipse Console Window Missing or poorly done (missing student name in screen shot) Program runs however may not be shown to work correctly. May only have part of the student’s name in the screen shot. Shows the program running successfully with correct outputs, based on inputs. Student’s full name is visible in the screen shot. Submission Missing Student does not provide both MS Word and .java file(s) with their submission, and/or does not follow lab professor’s submission requirements. Student does provide both the MS Word document and .java file(s) with their submission, and does follow lab professor’s submission requirements. References [1] Cay Horstmann. (2019). Big Java Early Objects. 7th Ed. Wiley. [2] Joyce Farrell. (2018). Programming Logic & Design Comprehensive. 9th Ed. Cengage Learning. Appendix: Sample of Program Running

$25.00 View

[SOLVED] Homework 8. amath 301 beginning scientific computing

Written Exercises (12 points total) Exercise 1. (Component Skill 8.1) The hyperbolic cosine is defined as cosh(x) = e x + e −x 2 . (Pronounced “kawsh of x.”) Calculate the fourth-degree Taylor polynomial of cosh(x) at x = 0. Exercise 2. (Component Skill 8.2) Consider the integral I = ∫ π 2 0 sin(x)dx. a. What is the exact value of I? You don’t have to show how you obtained this value. b. Approximate I with the left-hand rule using N = 4 subintervals. Show how you set-up the left-hand rule. Write your answer in decimal form. Round to the nearest fourth decimal place. c. Does your answer from (b) overestimate or underestimate the exact value of I? Provide a brief justification as to why this is (besides that the calculations suggest that this is the case). d. What is the maximum possible error of your answer for (b)? Show how you obtained this maximum possible error. Note: This question is asking about the maximum possible error, not the exact error. Use the global error estimate for the left-hand rule. e. Approximate I with the right-hand rule using N = 4 subintervals. Show how you set-up the right-hand rule. Write your answer in decimal form. Round to the nearest fourth decimal place. f. Does your answer from (e) overestimate or underestimate the exact value of I? Provide a brief justification as to why this is (besides that the calculations suggest that this is the case). g. What is the maximum possible error of your answer for (e)? Show how you obtained this maximum possible error. Note: This question is asking about the maximum possible error, not the exact error. Use the global error estimate for the right-hand rule. 2 h. Approximate I with the midpoint rule using N = 4 subintervals. Show how you set-up the midpoint rule. Write your answer in decimal form. Round to the nearest fourth decimal place. i. What is the maximum possible error of your answer for (h)? Show how you obtained this maximum possible error. Note: This question is asking about the maximum possible error, not the exact error. Use the global error estimate for the midpoint rule. Exercise 3. (Component Skills 8.3-8.4) Consider an ellipse of the form x 2 a 2 + y 2 b 2 = 1. The circumference of this ellipse is given by the integral C = ∫ 2π 0 √ a 2 sin2 (θ) + b 2 cos2(θ)dθ. This integral can be solved exactly if the ellipse is a circle. Then, a and b are equal to the radius of the circle r, and the circumference C = 2πr, as you learned in your grade school days. If a and b are not equal to each other, then we can’t solve the integral above exactly. a. Estimate C by the trapezoidal rule with N = 4 subintervals. Assume a and b are positive parameters. What you will find is an approximate formula for C as a function of a and b. b. Estimate C by Simpson’s 1/3 rule with N = 4 subintervals. Assume a and b are positive parameters. What you will find is an approximate formula for C as a function of a and b. 3 Coding Exercises (8 points total) Exercise 1. (Component Skills 8.2-8.4) The birth weight of a newborn kitten is normally distributed with a mean of µ = 3.5 ounces and a standard deviation of σ = 0.7 ounces. To compute the probability that a randomly selected newborn kitten is a heckin’ chonk like Sally with weight between 4.5 and 6 ounces, you would need to compute the integral P = ∫ 6 4.5 e −(x−µ) 2 2σ2 σ √ 2π dx. This integral cannot be evaluated exactly using any of the methods you learned in your calculus classes, so we will evaluate it using numerical integration. a. Use the MATLAB built-in function integral to estimate the “exact” value of P. Assign A1 to this value. Answer: b. Use the midpoint rule to approximate P with N = 2, 4, 8, 16, and 32 subintervals. Assign the variable A2 to a 5 × 1 column vector containing your approximations of P for each step size. Answer: c. Assign the variable A3 to a 5 × 1 column vector containing the errors of your approximations from (b). Define the error to be the difference in absolute value of the approximations obtained in (b) minus the exact value of the integral obtained in (a). Answer: 4 d. Use the trapesoidal rule to approximate P with N = 2, 4, 8, 16, and 32 subintervals. Assign the variable A4 to a 5×1 column vector containing your approximations of P for each step size. Note: Please use the MATLAB built-in function trapz. Answer: e. Assign the variable A5 to a 5 × 1 column vector containing the errors of your approximations from (d). Define the error to be the difference in absolute value of the approximations obtained in (d) minus the exact value of the integral obtained in (a). Answer: f. Use Simpson’s 1/3 rule to approximate P with N = 2, 4, 8, 16, and 32 subintervals. Assign the variable A6 to a 5×1 column vector containing your approximations of P for each step size. Answer: g. Assign the variable A7 to a 5 × 1 column vector containing the errors of your approximations from (f). Define the error to be the difference in absolute value of the approximations obtained 5 in (f) minus the exact value of the integral obtained in (a). Answer: h. Create the a plot in MATLAB that meets the following specifications: • Plot A3 as a function of N. Instead of the usual plot command, use semilogy to create a plot with a logarithmic scale on the y-axis. Adjust the line width to 2. Use blue for the line color. • Superimpose a plot of A5 as a function of N. Instead of the usual plot command, use semilogy to create a plot with a logarithmic scale on the y-axis. Adjust the line width to 2. Use red for the line color. • Superimpose a plot of A7 as a function of N. Instead of the usual plot command, use semilogy to create a plot with a logarithmic scale on the y-axis. Adjust the line width to 2. Use black for the line color. • Add a legend in the northeast corner of the graph. Use the label “Midpoint” for the first plot, the label “Trapezoid” for the second plot, and the label “Simpson” for the third plot. • Set the domain of the plot to be 0 ≤ N ≤ 33. Set the range of the plot to be 10−8 ≤ y ≤ 10−1 . Set the font size to 10. • Add the label “N” for the x-axis and the label “log10(error)” for the y-axis. Set the font sizes of these labels to 20. Add the title “Error of Numerical Integration Methods.” Set the font size to 20. • Turn on the grid and box. Answer:

$25.00 View

[SOLVED] Homework 7. amath 301 beginning scientific computing

Written Exercises (13 points total) Exercise 1. (Component Skill 7.1) Consider f(x) = 3x 3 − 2x 2 + 3x − 2 over the interval 0 ≤ x ≤ 4. a. What is the exact root of f in this interval? Hint: Factor by grouping. b. In what interval is the root guaranteed to be after three iterations of the bisection method? c. Based on your answer to (b), what is the best guess for the root of f after three iterations of the bisection method? d. What is the maximum possible error of your answer to (c)? e. How many iterations of the bisection method are needed to guarantee that the maximum possible error of the best guess of the root of f is less than 10−6? Exercise 2. (Component Skills 7.2-7.3) Consider again f(x) = 3x 3 − 2x 2 + 3x − 2. a. Perform one iteration of Newton’s method with initial guess x0 = 1. b. A grad student is concerned that there is an initial guess x0 such that f ′(xk) = 0 for some k ≥ 0. In such a situation, Newton’s method will fail. Explain why the grad student has nothing to worry about. Hint: Consider the values of x such that f ′(x) = 0. c. Perform one iteration of the secant method with initial guesses x0 = 0 and x1 = 1. Exercise 3. (Component Skill 7.4) Consider yet again f(x) = 3x 3 − 2x 2 + 3x − 2. 2 a. A grad student wants to solve f(x) = 0 by fixed point iteration. They naively choose the following fixed point form: x = 3x 3 − 2x 2 + 4x − 2, which inspires the iteration scheme xk+1 = 3x 3 k − 2x 2 k + 4xk − 2. Does this fixed point iteration converge for any initial guess x0 (assuming x0 is not exactly the root of f)? Perform a small calculation to justify your answer. b. A postdoc tries to fix the grad student’s mistake by proposing the following fixed point form: x = −x 3 + 2 3 x 2 + 2 3 , which inspires the iteration scheme xk+1 = −x 3 k + 2 3 x 2 k + 2 3 . Does this fixed point iteration converge for all initial guesses sufficiently close to the root of f? Perform a small calculation to justify your answer. c. A professor tries to improve convergence of the postdoc’s scheme by proposing the following fixed point form: x = ( 2 3 x 2 − x + 2 3 ) 1 3 , which inspires the iteration scheme xk+1 = ( 2 3 x 2 k − xk + 2 3 ) 1 3 . Does this fixed point iteration converge faster than the postdoc’s for all initial guesses sufficiently close to the root of f? Perform a small calculation to justify your answer. Hint: Use WolframAlpha to calculate and/or evaluate any derivatives you need to take. 3 Coding Exercises (7 points total) Exercise 1. (Component Skills 7.1-7.3, 7.5) A former TA of this class studied caterpillar life cycles. She encountered the following equation in her research: 6 − 3x(1 + e 3(1−x) ) = 0. (1) Here, x represents the population of caterpillars in thousands. By guess and check, one can see that x = 1 is a solution of (1). There are two other nontrivial solutions x1 and x2. We take x2 > x1 without loss of generality. a. Use the MATLAB built-in function fzero with initial guess 0.1 to determine the value of x1. Assign A1 to the value of x1. Answer: b. Use the MATLAB built-in function fzero with initial guess 1.9 to determine the value of x2. Assign A2 to the value of x2. Answer: c. Copy the MATLAB function bisectionMethod from the weekly lecture notes. Paste this function at the very bottom of your hw7.m script. Use this function to perform the bisection method on the function f(x) given by the LHS of (1). Take the initial interval to be 0 ≤ x ≤ 0.5. Set the stop criterion to 10−15. Assign A3 to the approximation of the root x1 according to the bisection method. Assign A4 to the number of iterations necessary to satisfy the stop criterion. Answer: 4 d. Repeat (c) but take the initial interval to be 1.5 ≤ x ≤ 2. Set the stop criterion to 10−15 . Assign A5 to the approximation of the root x2 according to the bisection method. Assign A6 to the number of iterations necessary to satisfy the stop criterion. Answer: e. Copy the MATLAB function newtonMethod from the weekly lecture notes. Modify the function so that the Cauchy error is used as the stopping criterion. Have your function return the approximation of the root according to Newton’s method as well as the number of iterations necessary to satisfy the stop criterion. Once your function has been modified appropriately, paste this function at the very bottom of your hw7.m script. Use this function to perform the Newton’s method on the function f(x) given by the LHS of (1). Take the initial guess to be x0 = 0.1. Set the stop criterion to 10−15 . Assign A7 to the approximation of the root x1 according to Newton’s method. Assign A8 to the number of iterations necessary to satisfy the stop criterion. Note: You will need to compute f ′(x) by hand and write this as a function handle to run Newton’s method in MATLAB. Answer: 5 f. Repeat (e) but take the initial guess to be x0 = 1.9. Set the stop criterion to 10−15. Assign A9 to the approximation of the root x2 according to Newton’s method. Assign A10 to the number of iterations necessary to satisfy the stop criterion. Answer: g. Create your own MATLAB function secantMethod. The function should have the following inputs: • a function handle for the function whose root is to be found, • an initial guess for the root, • a second guess for the root, and • a threshold for the Cauchy error. The function should output the following: • the approximate value of the root according to the secant method and • the number of iterations necessary to satisfy the threshold for the Cauchy error. Paste your function at the very bottom of your hw7.m script. Use this function to perform the secant method on the function f(x) given by the LHS of (1). Take the initial guess to be x0 = 0.1, the second guess to be x1 = 0.11, and the stop criterion to be 10−15. Assign A11 to the approximation of the root x1 according to the secant method. Assign A12 to the number of iterations necessary to satisfy the stop criterion. Answer: 6 h. Repeat (g) but take the initial guess to be x0 = 1.9 and second guess to be x1 = 1.8. Set the stop criterion to 10−15. Assign A13 to the approximation of the root x2 according to the secant method. Assign A14 to the number of iterations necessary to satisfy the stop criterion. Answer:

$25.00 View

[SOLVED] Homework 6. amath 301 beginning scientific computing

Written Exercises (13 points total) Exercise 1. (Component Skill 6.1) A tornado passes over a weather station with a barometer that was recording atmospheric pressure as a function of time1 . Several weeks after the storm passed and clean-up efforts concluded, meteorologists at the weather station fit the pressure data to a curve and found the following relationship: p(t) = 1 − 12t 57 + 16(t − 2) 2 . Here, t is time in minutes after the tornado sirens first went off, and p(t) is the atmospheric pressure (measured in standard atmospheres) at the weather station. The tornado destroyed the barometer after t = 3 minutes, so the relationship above is valid only for 0 ≤ t ≤ 3. a. Is p(t) a unimodal function over 0 ≤ t ≤ 3? Justify your answer by finding the critical point(s) of p(t) over the interval 0 ≤ t ≤ 3. Hint: Please use Wolfram Alpha to calculate p ′(t). b. Show that your critical point from (b) is a local minimum using the second derivative test. Hint: Please use Wolfram Alpha to calculate p ′′(t). c. What is the minimum pressure recorded at the weather station over 0 ≤ t ≤ 3? Don’t forget to check the boundaries of the interval! d. What is the maximum pressure recorded at the weather station over 0 ≤ t ≤ 3? Don’t forget to check the boundaries of the interval! e. The tornado is right on top of the weather station when the pressure is minimized. At what time does the tornado arrive at the weather station? Exercise 2. (Component Skills 6.2-6.3) Consider the function f(x) = ∣x − 1∣ defined over the interval −2 ≤ x ≤ 6. a. Perform three iterations of the three-point equal interval search by hand. What interval is guaranteed to contain the value of x that corresponds to the minimum of f after three iterations of the three-point equal interval search? 1 Ironic, I know. 2 b. Perform one iteration of successive parabolic interpolation if f is sampled initially at x1 = 0, x2 = 2, and x3 = 4. Based on this one iteration, at what value of x does f attain a minimum? Exercise 3. (Component Skill 6.4) Consider the quadratic polynomial f(x) = ax2 , with free parameter a > 0. Clearly, this quadratic has a global minimum at x = 0. a. Set a = 1. Perform three iterations of gradient descent by hand with initial guess x0 = 1 and learning rate γ = 1/4. Does gradient descent appear to be converging? b. Set a = 1. Perform three iterations of gradient descent by hand with initial guess x0 = 1 and learning rate γ = 1. Does gradient descent appear to be converging? c. According to Theorem 6.4.1 in the weekly lecture notes, the learning rate γ must be strictly less than 1/L for gradient descent to converge, where L is the maximum of ∣f ′′(x)∣. Use this theorem to explain why (a) converged and (b) did not. d. According to Theorem 6.4.2 in the weekly lecture notes, ∣f(xk) − f(x∗)∣ ≤ (x0 − x∗) 2 2γk , where x∗ is the exact x-coordinate of the minimum, xk is the kth iterate of gradient descent, x0 is the initial guess, and γ is the learning rate. The expression on the LHS of this inequality can be thought of as the error between the exact minimum of f and what gradient descent predicts is the minimum of f after k iterations. Given f(x) = x 2 , x0 = 1, x∗ = 0, and γ = 1/4, how many iterations of gradient descent are necessary to guarantee that ∣f(xk) − f(x∗)∣ < 10−15? Hint: Find the exact k such that the RHS of the inequality equals 10−15 . 3 Coding Exercises (7 points total) Exercise 1. (Component Skills 6.2-6.4) A seminal breakthrough in HIV treatment was the use of multiple-drug combination therapy. The idea behind the therapy is that multiple drugs, when introduced to the body at specific times, fight the virus off better than one drug alone. A key step in the development of multiple-drug therapy was to determine the best time to take the next drug. One way this is done is to take the next drug when the previous drug is at its maximum concentration in the body. Suppose the concentration of the first drug in the therapy is modeled by x(t) = 10 3 (e − t 24 − e − t 2 ) . Here, x(t) represents the concentration of the first drug in the body (in mol/L) and t is time in hours since the initial injection of the first drug. Assume that we want to administer our second drug when x(t) is at its maximum. Let’s call this time tmax. a. In order to find tmax, we need to convert this maximization problem into a minimization problem. This can be done by introducing y(t) = −x(t). Note that the minimum of y(t) occurs at t = tmax. Copy my function file threePtSearch from the weekly lecture notes. Place this function file at the very bottom of your hw6.m script. Modify this function to return not only the variable int, but also the number of iterations N needed to achieve the desired error threshold. Use this function to compute a three-point equal interval search for the minimum of y(t) over the interval 0 ≤ t ≤ 12. Set the error threshold to ε = 10−3 . Assign the variable A1 to the interval returned by the threePtSearch function. Assign A2 to the midpoint of A1. Assign the variable A3 to the number of iterations of the three-point equal interval search. Answers: 4 b. Copy my function file succParInt from the weekly lecture notes. Place this function file at the very bottom of your hw6.m script. Modify this function to return not only the variable int, but also the number of iterations N needed to achieve the desired error threshold. Use this function to compute find the minimum of y(t) by successive parabolic interpolation. Set the initial sample points to be t1 = 3, t2 = 6, and t3 = 9. Set the error threshold to ε = 10−3 . Assign the variable A4 to the interval returned by the threePtSearch function. Assign A5 to the midpoint of A4. Assign the variable A6 to the number of iterations of the successive parabolic interpolation. Answers: c. Copy my function file gradDescent from the weekly lecture notes. Place this function file at the very bottom of your hw6.m script. Calculate y ′(t) by hand. (You don’t have to show your work for this.) Use y ′(t) to perform gradient descent on y(t). Take the initial guess for the minimum to be t0 = 1. Set the learning rate to be γ = 20 and the Cauchy error threshold to be ε = 10−3 . Assign the variable A7 to the value of the minimum of y(t) according to gradient descent. Answers:

$25.00 View

[SOLVED] Homework 5. amath 301 beginning scientific computing

Written Exercises (7 points total) Exercise 1. (Component Skill 5.1) Solve the following least-squares problem: ⎛ ⎜ ⎝ 1 0 0 1 1 1 ⎞ ⎟ ⎠ ( x1 x2 ) = ⎛ ⎜ ⎝ 1 1 0 ⎞ ⎟ ⎠ . Show how you arrived at the normal equation. Once there, you can just report the solution of the linear system. Exercise 2. (Component Skill 5.2) The following data represents the temperature T (in oC) in Seattle t hours after sunrise: t T 0 0 1 0 2 2 What is the equation of the line that fits these data points and minimizes the least-squares error? Show how your arrived at the normal equation. Once there, you can just report the solution of the linear system. Exercise 3. (Component Skill 5.3) Suppose we sample y = sin2 (x) at x = 0, x = π/4, and x = π/2. We obtain the following data: x y 0 0 π/4 1/2 π/2 1 a. Fit the data points above to the curve y = a + b cos(2x). Determine a and b that minimize the least-squares error. Show how you arrived at the normal equation. Once there, you can just report the solution of the linear system. b. The values of a and b you found in (a) should not surprise you. Give a one sentence explanation for why you should not be surprised. 2 Coding Exercises (13 points total) Exercise 1. (Component Skill 5.3) The file salmon_data.mat contains the annual count of Chinook salmon taken at Bonneville on the Columbia river from the years 1938 to 2020. In this problem, we will fit these data with various polynomial curves to predict the salmon population in 2021. a. Download the file salmon_data.mat from the Homework 5 page on Canvas. Make sure this file is in the same folder as your hw5.m script. In the Exercise 1 section of your hw5.m script, type load(‘salmon_data.mat’); This will automatically create two variables. The first variable is called salmon. This is an 83 × 1 column vector of the annual salmon count taken at Bonneville. The second variable is called year. This is an 83×1 column vector of the corresponding years for which the salmon count was recorded. Treating salmon as the y-variable and year as the x-variable, use the MATLAB built-in function polyfit to find the coefficients of the first-degree polynomial that best fits the salmon data in the least-squares sense. Assign the row vector of coefficients of this first-degree polynomial to the variable A1. You may get MATLAB warnings about the polynomial being badly conditioned. Normally, we’d heed these warnings, but let’s ignore them for the purposes of this exercise. Answer: b. Use the MATLAB built-in function polyfit to find the coefficients of the third-degree polynomial that best fits the salmon data in the least-squares sense. Assign the row vector of coefficients of this third-degree polynomial to the variable A2. 3 Answer: c. Use the MATLAB built-in function polyfit to find the coefficients of the fifth-degree polynomial that best fits the salmon data in the least-squares sense. Assign the row vector of coefficients of this fifth-degree polynomial to the variable A3. Answer: d. Assuming (a)-(c) are correct, you now have three polynomials that approximate the count of Chinook salmon as a function of the year: a linear polynomial, a cubic polynomial, and a quintic polynomial. Call these polynomials p1, p3, and p5, respectively. Let’s test the predictive power of these polynomials. The number of Chinook salmon in 2021 was 489,523. For each of your three polynomials, calculate the relative error between what your polynomial predicts is the salmon count in 2021 and what the true salmon count is. In other words, calculate ϵ1 = ∣p1(2021) − 489523∣ 489523 , ϵ2 = ∣p3(2021) − 489523∣ 489523 , and ϵ3 = ∣p5(2021) − 489523∣ 489523 . Use the MATLAB built-in function polyval to evaluate your polynomials. Assign the variable A4 to the 3 × 1 row vector [ϵ1, ϵ2, ϵ3]. 4 Answer: Exercise 2. (Component Skill 5.3) The amount of CO2 in the atmosphere is measured at the Mauna Loa observatory in Hawaii in parts per million (ppm). The file CO2_data.mat contains the monthly average CO2 concentrations from March 1958 to December 20201. A plot of the data is shown below. Clearly, there is an overall increasing trend in CO2 concentrations as well as small seasonal oscillations. In this exercise, we fit the data to an exponential curve to capture the overall increasing trend in CO2 concentrations. Figure 1: Monthly average concentration of atmospheric CO2 in ppm as a function of time a. Download the file CO2_data.mat from the Homework 5 page on Canvas. Make sure his file is in the same folder as your hw5.m script. In the Exercise 2 section of your hw5.m script, type load(‘CO2_data.mat’); 5 This will automatically create two variables. The first variable is called CO2. This is a 753 × 1 column vector of monthly averaged CO2 measurements (in parts per million). The second variable is called year. This is a 753 × 1 column vector of time in years since January 1958. These times correspond to when the CO2 measurements were taken. Treating CO2 as the y-variable and year as the x-variable, suppose we fit the data with an exponential curve of the form y = aerx + b. Create a function handle that takes in a 3×1 column vector whose first component is a, second component is r, and third component is b and returns the least-squares error of the exponential fit to the data. Use the MATLAB built-in function fminsearch to find the values of a, r, and b that minimize the least-squares error. Use the initial guess [30; 0.03; 300]. Assign the variable A5 to the column vector [a; r; b]. Answer: b. Repeat (a) but using the L1 error instead of the least-squares error. Assign the variable A6 to the column vector [a; r; b]. Answer: c. Let’s plot our results from (a) and (b). Do the following in order: • Plot the CO2 data in black. Use ‘.’ for the ‘Marker’ option and ‘none’ for the ‘LineStyle’ option. Set the domain to 0 ≤ x ≤ 63. Set the range to 300 ≤ y ≤ 420. • Superimpose your exponential curve from (a) to the plot of the CO2 data. Be sure to sample this curve with enough points to appear continuous. Plot this exponential curve in red. Set the ‘LineWidth’ option to 2. 6 • Superimpose your exponential curve from (b) to the plot of the CO2 data and your exponential curve from (a). Be sure to sample this curve with enough points to appear continuous. Plot this exponential curve in blue. Set the ‘LineWidth’ option to 2. Set the ‘LineStyle’ option to ‘–’. • Add a legend that distinguishes your two exponential curves. Label your exponential curve from (a) ‘LSE’ for “least-squares error.” Label your exponential curve from (b) ‘L1E’ for “L1 error.” Move the legend to the northwest corner of the plot. • Create a x-axis label ‘Years since 1958’. Create a y-axis label ‘CO_2 Concentration (ppm)’. Set the font size of both labels to 16. Create a title ‘CO_2 Concentration vs. Time’. Set the font size of the title to 20. • Turn on the grid and box. Answer: 7 Exercise 3. (Component Skill 5.3) Hanging from one of Sally’s cat towers is a spring with a small toy connected at its end. When the toy is vertically displaced, it oscillates up and down until eventually settling back to equilibrium because of friction and air resistance. Sally is very interested in the behavior of her oscillating toy and has taken careful measurements of its displacement as a function of time. These measurements can be found in the file spring_data.mat. a. Download the file spring_data.mat from the Homework 5 page on Canvas. Make sure his file is in the same folder as your hw5.m script. In the Exercise 3 section of your hw5.m script, type load(‘spring_data.mat’); This will automatically create two variables. The first variable is called deltaz. This is a 51 × 1 column vector of vertical displacements in centimeters. The second variable is called time. This is a 51 × 1 column vector of time in seconds. These times correspond to the measured displacements. Sally has a suspicion that her toy’s maximum displacement below its equilibrium position happens at time t = π/2 seconds. She’d like to obtain the value of this displacement to know where to strike during play time. Unfortunately for Sally, she has no measurements of displacement at exactly t = π/2 seconds. Her closest measurements are at t = 1.4 seconds and t = 1.6 seconds. Thus, she’s going to need to interpolate. Using the MATLAB built-in function interp1, help Sally estimate the value of the toy displacement at t = π/2 seconds using a cubic spline interpolation. Assign the value of this displacement to the variable A7. Answer: b. Help Sally create a plot of her data and cubic spline interpolation. Do the following in order: • Plot the cubic spline interpolation of the displacement data in blue. Use the MATLAB built-in function interp1 with sample points t = 0:0.01:10 to construct this cubic spline interpolation. Adjust the ‘LineWidth’ option to 2. Set the domain to 0 ≤ x ≤ 10. Set the range to −1 ≤ y ≤ 1. • Superimpose the displacement data to your cubic spline plot. Plot the displacement data in black. Use ‘.’ for the ‘Marker’ option and ‘none’ for the ‘LineStyle’ option. Adjust the ‘MarkerSize’ option to 15. • Create a x-axis label ‘Time (s)’. Create a y-axis label ‘Vertical Displacement (cm)’. Set the font size of both labels to 16. Create a title ‘Vertical Displacement vs. Time’. Set the font size of the title to 20. 8 • Turn on the grid and box. Answer:

$25.00 View

[SOLVED] Homework 4. amath 301 beginning scientific computing

Written Exercises (10 points total) Exercise 1. (Component Skill 4.1) Consider the following ridiculously simple linear system: ( 1 0 0 2) (x1 x2 ) = ( 1 1 ) . a. What is the solution of this linear system? You don’t have to show your work. b. Set up a Neumann iteration with initial guess x0 = (0, 0) T . Calculate x1, x2, x3, and x4. Show your work. c. Based on your calculations in (b), what will xk equal for k > 0 when (i) k is odd and (ii) k is even? You don’t have to show your work. d. Based on your answer to (c), does the Neumann iteration converge? e. Let M represent the matrix used in your Neumann iteration. Does Mn → 0 as n → ∞? What does this tell you about the convergence of the Neumann iteration method? Is this consistent with your answer to (d)? Exercise 2. (Component Skill 4.2) For each linear system, decide whether Jacobi iteration is guaranteed or not guaranteed to converge to the solution. Justify each of your decisions in a sentence or two. a. ⎛ ⎜ ⎝ 3 1 0 1 3 1 0 1 3 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ b. ⎛ ⎜ ⎝ −3 1 0 1 −3 1 0 1 −3 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ c. ⎛ ⎜ ⎝ 1 3 0 3 1 3 0 3 1 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ d. ⎛ ⎜ ⎝ 1 −3 0 −3 1 −3 0 −3 1 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ e. ⎛ ⎜ ⎝ 2 1 0 1 2 1 0 1 2 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ 2 Coding Exercises (10 points total) Exercise 1. (Component Skill 4.2) The following MATLAB function file executes Jacobi iteration: 1 function [ x1 ] = JacobiHW4 (A ,b , x0 ,N ) 2 % INPUTS : A is a nxn coefficient matrix 3 % b is a nx1 column vector of knowns 4 % x0 is the nx1 initial guess of the solution 5 % N is the number of iterations 6 % OUTPUTS : x1 is the nx1 solution 7 8 D = diag ( diag ( A ) ) ; 9 L = tril (A , -1) ; 10 U = triu (A ,1) ; 11 12 for j = 1: N 13 x1 = D ( -( L + U ) * x0 + b ); 14 x0 = x1 ; 15 end 16 17 end a. Use the function above to solve ⎛ ⎜ ⎝ 3 1 0 1 3 1 0 1 3 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ (1) by Jacobi iteration. Be sure to put the code for the function at the very bottom of your hw4 script file. Take the initial guess to be x0 = (0, 0, 0) T and iterate N = 10 times. Assign the value of x10 to the variable A1. Use format long to show as many decimal places as possible. b. What is the exact solution of (1) according to the MATLAB backslash command? Assign this solution to the variable A2. c. Let x∗ be the exact solution of (1). Define the error of the kth Jacobi iterate xk as the maximum difference in absolute value between corresponding components of xk and x∗: E = max 1≤i≤3 {∣xk,i − x∗,i∣} . Assign the variable A3 to the value of E for your x10 computed in (a). Use format long to show as many decimal places as possible. 3 Answers: Exercise 2. (Component Skill 4.3) Modify the Jacobi function file given in Coding Exercise 1 to create a new function file in MATLAB that executes Gauss-Seidel iteration. Call your new function file GaussSeidelHW4. Retain the same inputs and output as before. a. Use your new function to solve ⎛ ⎜ ⎝ 3 1 0 1 3 1 0 1 3 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ (2) by Gauss-Seidel iteration. Be sure to put the code for your function at the very bottom of your hw4 script file. Take the initial guess to be x0 = (0, 0, 0) T and iterate N = 10 times. Assign the value of x10 to the variable A4. Use format long to show as many decimal places as possible. b. Let x∗ be the exact solution of (2). Define the error of the kth Gauss-Seidel iterate xk as the maximum difference in absolute value between corresponding components of xk and x∗: E = max 1≤i≤3 {∣xk,i − x∗,i∣} . Assign the variable A5 to the value of E for your x10 computed in (a). How does this error compare to your error in Coding Exercise 1(c)? Use format long to show as many decimal places as possible. 4 Answers: Exercise 3. (Component Skill 4.4) Modify the Jacobi function file given in Written Exercise 3 to create a new function file in MATLAB that executes SOR iteration. Call your new function file SORHW4. Retain the same inputs as before, but add one more input ω for the relaxation parameter. Keep the output the same. a. Use your new function to solve ⎛ ⎜ ⎝ 3 1 0 1 3 1 0 1 3 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ (3) by SOR iteration with ω = 1.09. Be sure to put the code for your function at the very bottom of your hw4 script file. Take the initial guess to be x0 = (0, 0, 0) T and iterate N = 10 times. Assign the value of x10 to the variable A6. Use format long to show as many decimal places as possible. Remark: For this linear system, ω = 1.09 is very close to the optimal choice. b. Let x∗ be the exact solution of (3). Define the error of the kth SOR iterate xk as the maximum difference in absolute value between corresponding components of xk and x∗: E = max 1≤i≤3 {∣xk,i − x∗,i∣} . Assign the variable A7 to the value of E for your x10 computed in (a). How does this error compare to your errors in Coding Exercises 1(c) and 2(b)? Use format long to show as many decimal places as possible. 5 Answers: Exercise 4. (Component Skill 4.2) Rather than specify the number of Jacobi iterations, we could specify a desired error threshold to achieve instead. In particular, if the kth Jacobi iterate is within this specified threshold of error of the true solution, we terminate our Jacobi iterations. It’s a great idea, but the problem is that we usually don’t know the exact solution of our linear system and, hence, can’t exactly measure the error of our kth iteration. What we do instead is we keep track of what’s called the Cauchy error. This is the maximum difference in absolute value between two successive Jacobi iterations: C = max i ∣xk,i − xk−1,i∣. Here, the index i keeps track of the components of our iterates. If the Cauchy error is decreasing, our iterates must be converging closer and closer to the exact solution of the linear system. The following represents a MATLAB function file that executes Jacobi iteration until the Cauchy error falls below a certain threshold: 1 function [ x1 , N ] = JacobiCauchyHW4 (A ,b , x0 , threshold ) 2 % INPUTS : A is a nxn coefficient matrix 3 % b is a nx1 column vector of knowns 4 % x0 is the nx1 initial guess of the solution 5 % threshold is the Cauchy error threshold 6 % OUTPUTS : x1 is the nx1 solution 7 % N is the number of iterations 8 9 D = diag ( diag ( A ) ) ; 10 L = tril (A , -1) ; 11 U = triu (A ,1) ; 12 13 x1 = D ( -( L + U ) * x0 + b ); 14 err = max ( abs ( x1 – x0 ) ) ; 15 N = 1; 6 16 17 while err > threshold 18 xtemp = x1 ; 19 x1 = D ( -( L + U ) * x1 + b ); 20 x0 = xtemp ; 21 err = max ( abs ( x1 – x0 )) ; 22 N = N +1; 23 end 24 25 end a. Use the function above to solve ⎛ ⎜ ⎝ 3 1 0 1 3 1 0 1 3 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ by Jacobi iteration. Be sure to put the code for the function above at the very bottom of your hw4 script file. Take the initial guess to be x0 = (0, 0, 0) T and the error threshold to be 10−10 . Assign the number of iterations necessary to achieve this error threshold to the variable A8. b. Modify the function above to solve ⎛ ⎜ ⎝ 3 1 0 1 3 1 0 1 3 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ by Gauss-Seidel iteration. Call your new function GaussSeidelCauchyHW4. Be sure to put the code for your function at the very bottom of your hw4 script file. Take the initial guess to be x0 = (0, 0, 0) T and the error threshold to be 10−10. Assign the number of iterations necessary to achieve this error threshold to the variable A9. Compare your answer with (a). c. Modify the function above to solve ⎛ ⎜ ⎝ 3 1 0 1 3 1 0 1 3 ⎞ ⎟ ⎠ ⎛ ⎜ ⎝ x1 x2 x3 ⎞ ⎟ ⎠ = ⎛ ⎜ ⎝ 1 1 1 ⎞ ⎟ ⎠ by SOR iteration. Call your new function SORCauchyHW4. Make sure you add an extra input for the relaxation parameter ω. Be sure to put the code for your function at the very bottom of your hw4 script file. Take the initial guess to be x0 = (0, 0, 0) T , the relaxation parameter to be ω = 1.09, and the error threshold to be 10−10. Assign the number of iterations necessary to achieve this error threshold to the variable A10. Compare your answer with (a) and (b). 7 Answers: 8

$25.00 View

[SOLVED] Cst8116 assignment 03

Using Git within Eclipse.Complete the tasks below accurately and in order. Refer to the relevant hybrid activities resources if needed.  C:CST8116_Assignment_03_Your_Name           Do not fix this exception just yet.         C:CST8116_Assignment_03_Your_NameUse the rubric below to verify the files you are required to submit:  Once verified, submit all 3 files and look for a confirmation email on your submission. 

$25.00 View

[SOLVED] Math 231 — hw 18

1. In class, we discussed the differential operator, D, over the space P3, the space of polynomials up to degree 3. The differential operator takes polynomials to their derivatives. Solve the following equation: D(ax3 + bx2 + cx + d) = 2. If ax3 + bx2 + cx + d is represented as the column vector   a b c d   , write out M(D). (Hint: Use your previous answer.) 3. In class, we stated that the null D is the space of constant functions. What is the representation of this null space? In other words, what is null M(D)? 4. Suppose S is a map that represents a shift in vectors over R 3 . S(a, b, c) = (b, c, 0). Describe its null space and give a representation M(S). 5. Now suppose we define a function P that represents a permutation over the vector space R 3 . P(a, b, c) = (b, c, a). Describe its null space and give a representation M(P).

$25.00 View

[SOLVED] Math 231 — hw 17

The null space is the space of all vectors that are sent to 0 by a matrix. For example, the null space of  2 4 −1 −2  is the set of vectors of the form  2x −x  . To demonstrate this, we see that  2 4 −1 −2   2 −1  =  0 0  . 1. Consider the following matrices. What is their null space? Based on their null space, do their column vectors form a basis? (a)  3 3 −1 −1  (b)   1 0 1 0 1 1 1 1 2   2. If a null space has more than just the 0 vector, we call it “nontrivial.” Give the basis of the nontrivial null space of the following matrix  1 −1 2 3 −3 6 3. Suppose M is a 3 × 3 matrix. We said in class that M can be thought of as changing the basis of the matrix. For this reason, the columns of M represent a basis. If the null space is nontrivial, then the vectors don’t form a basis of the 3 dimensional vector space. What does that mean about dimensionality of the range of M? 4. Based on your answer to the previous question, what does it mean geometrically if a matrix has a nontrivial null space? 5. To capture rotations in two dimensions, we can use the following matrix:  cos θ − sin θ sin θ cos θ  Suppose a camera is pointed downward looking at a specimen located at (2, 3). If the camera is rotated by 240 degrees in the positive direction, what is the vector that represents its location with this new orientation?

$25.00 View

[SOLVED] Math 231 — hw 16

In class, we continued to discuss how we to use matrix representations of linear maps between vector spaces. Suppose we define the horrible map you came up with in class, T : R 4 → R 3 • T(1, 2, 3, 4) = (5, 6, 7) • T(11, 10, 9, 8) = (2, 3, 1) • T(1, 5, 7, 2) = (7, 8, 6) • T(0, 0, 0, 1) = (9, 1, 1) Our strategy for handling this is to define a map U : R 4 → R 4 that translates from a nice basis {(1, 0, 0, 0),(0, 1, 0, 0), …} to the basis upon which T is defined: {(1, 2, 3, 4),(11, 10, 9, 8), …}. We did this in class and defined the matrix representation for U to be M(U) =   25 24 −17 6 15 8 0 1 24 1 6 −1 8 0 −1 2 1 −1 2 0 −7 2 8 −11 2 1   If we define the set of mapped elements in R 3 to be {(5, 6, 7),(2, 3, 1),(7, 8, 6),(9, 1, 1)}, then the matrix representation of T is M(T) =   1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1   But this is not enough to get the full answer. Why? Suppose there is a vector v for which we apply M(U) and then M(T) and we get the result (1, 0, 1, 1). This vector represents: 1 · (5, 6, 7) + 0 · (2, 3, 1) + 1 · (7, 8, 6) + 1 · (9, 1, 1). Ideally we’d like the result to actually be our answer directly and not have to do this extra step. So we can define a map S that goes from {(5, 6, 7),(2, 3, 1),(7, 8, 6),(9, 1, 1)} to {(1, 0, 0),(0, 1, 0),(0, 0, 1)}. Define M(S).

$25.00 View

[SOLVED] Math 231 — hw 15

In class, we discussed how we to use matrix representations of linear maps between vector spaces. We did two examples in class. Below is the complete version of the second one with a small change to make the math easier. Suppose we have two vector spaces, V = Z 3 7 and W = R 2 , with the bases BV = {(1, 1, 1),(1, 6, 1),(0, 1, 1)} and BW = {(1, 0),(0, 1)}. I will use vi and wi to denote these elements. And we define the following linear map T between them: • T v1 = 3w1 • T v2 = w1 + 2w2 • T v3 = −w2 The matrix representation of T between these two spaces with those bases is M(T) =  3 1 0 0 -2 -1  The basis used for Z 3 7 in defining T is not ideal, so we’d like to construct a map U : Z 3 7 → Z 3 7 where we change the basis from the standard basis, {(1, 0, 0),(0, 1, 0),(0, 0, 1)} to BV . Then we can construct a map by composing T ◦ U to construct a map from Z 3 7 to R 3 . So we need to construct (1, 0, 0) as a linear combination of the elements in BV . In other words, we need to find elements x, y, z such that x + y = 1, x + 6y + z = 0, x + y + z = 0. From the first and third equation, we can deduce that z = 6. And then see that x = 1 and y = 0 works for our problem. Hence U((1, 0, 0)) = v1 + 6v3. By similar logic, we can get the remaining two: • U((1, 0, 0)) = v1 + 6v3. • U((0, 1, 0)) = 4v1 + 3v2. • U((0, 0, 1)) = v3. The matrix representation of U is M(U) =   1 1 0 0 3 0 0 0 1   1 Suppose we have the element v = (2, 3, 1) in Z 3 7 . Where does T map this element to? We can use the matrix representations and compute T ◦ U: T Uv =  3 1 0 0 -2 -1    1 1 0 0 3 0 0 0 1     2 3 1   =  3 1 0 0 -2 -1    5 2 1   =  17 -5  A tricky element here is that U is happening modulo 7 because of the spaces it is going between. Now it is your turn to try. 1. Consider the vector spaces V = Z 2 5 and W = R 3 with bases BV = {(1, 2),(0, 1)} and BW = {(1, 0, 0),(0, 1, 0),(0, 0, 1)}.Define the linear map T : V → W such that • T v1 = 2w1 + w3 • T v2 = w2 − w3 Let v = (3, 4) be a vector in V . Compute T v ∈ W using the matrix representation method.

$25.00 View

[SOLVED] Math 231 — hw 13

1. Suppose p0, p1, p2, p3 is a basis of the space of polynomials of degree 3. Construct a basis where none of the polynomials are degree 2. Recall: the degree of a polynomial is the term with the maximum degree, for example this polynomial is degree 3: x 3 + x 2 + x + 1. 2. Suppose {v1.v2, v3, v4} is basis of V . Prove that {v1 + v2, v2 + v3, v3 + v4, v4} is also a basis of V . 3. Suppose v1.v2, v3, v4 is basis of V . Prove that {v1, v1 + v2, v1 + v2 + v3, v1 + v2 + v3 + v4} is also a basis of V .

$25.00 View

[SOLVED] Math 231 — hw 11

1. In this video, the speaker explains that historically, rainbows in Western art were depicted with only three colors until Isaac Newton expanded the concept to seven. This shift highlights how different cultural and scientific perspectives influence our understanding of color. In modern computing, colors are represented mathematically using vector spaces such as RGB (Red-Green-Blue) and CMYK (Cyan-Magenta-Yellow-Black). We can approximate these models using the vector spaces R 3 and R 4 , respectively, where each coordinate represents a component’s intensity. For example, in RGB, the vector (1, 0, 0) represents pure red, while in CMYK, the vector (1, 0, 0, 0) represents pure cyan. The RGB and CMYK models describe color in fundamentally different ways: (a) RGB is an additive color model, where colors are created by combining light. (b) CMYK is a subtractive model, used in printing, where colors result from absorbing certain wavelengths. (c) What do you think it means in this context if a given set spans a set? Mathematically, could three distinct shades of a color we recognize, say three shades of red, be enough to span the entire space of colors? Pick three vectors in the RGB space with values between 0 and 1 (e.g., (.33, .25, 0)). Prove that your three vectors span R 3 . With the provided code, convert them to CMYK. Prove that the result does not span R 4 . 2. In music theory, chords can be represented as vectors in a musical space, where each coordinate represents the presence or absence of a particular note in a chord. Let’s look at the 5 chords within the B-minor scale famously used in the song “15 Step” from In Rainbows, Radiohead’s 7th album.1 Chord B C# D E F # G A Bm 1 0 1 0 1 0 0 Cdim5 0 1 0 1 0 1 0 A6 0 0 1 0 1 0 1 Gmaj7 0 0 1 0 1 1 1 (a) Are the given chord vectors linearly independent in R 7 ? Justify your answer. 1Fun fact: They released this album themselves (without a record label) and allowed customers to pay what they wanted for it. The band made a much bigger profit on this album than their previous ones. 1 (b) Do these chords span the space of all possible chords in the B minor scale (i.e., all possible vectors in R 7 with only 0s and 1s)? If not, add additional chords to the set in the provided code. Alternatively, feel free to create an entirely new set of chords from the basis that span. (c) What do you think it means in this context if a given set is linearly dependent?

$25.00 View

[SOLVED] Math 231 — hw 12

1. Consider the vector space F 2 2 . What are all the possible bases for this space? (You do not need to prove this). 2. Consider the linearly independent set in R 3 and construct a basis by adding one element to it. Then prove that it is a basis. {(1, 0, 1),(−1, 0, 1)} 3. Consider the linearly independent set in R 3 and construct a basis by adding one element to it. Then prove that it is a basis. {(1, −1, 1),(0, 1, 1)} 4. In the previous two examples, you wrote two distinct bases of R 3 . Given a vector (x, y, z) ∈ R 3 , write a set of functions fi(a1, a2, a3) = bi where each function takes in the coefficients of the first basis and produces the i th coefficient of the second basis. What kind of functions are these? 5. Prove or give a counterexample: If v1, v2, v3, v4 is a basis of V and U is a subspace of V such that v1, v2 ∈ U and v3 ̸∈ U and v4 ̸∈ U, then v1, v2 is a basis of U.

$25.00 View

[SOLVED] Math 231 — hw 10

1. Is the following set of vectors from R 3 a linearly independent set? {(1, 2, 3),(4, 5, 6),(7, 8, 9)} Prove or disprove. 2. Remember that vectors are just elements of a vector space. Since P2, the space of polynomials up to degree 2, is a vector space, then below is a set of vectors from that space. S = {2, x − 1, x2 − x} Is it true that span(S) = P2. Prove your answer.

$25.00 View

[SOLVED] Math 231 — hw 8

1. Let V be a vector space and 0 ∈ V the additive identity. Prove that 0 + 0 = 0. Then prove that 0 + . . . + 0 = 0 for any finite number of sums. 2. Let V = R 3 and consider the subspaces: W1 = {(x, y, 0) | x, y ∈ R}, W2 = {(0, 0, z) | z ∈ R}. Prove that V = W1 ⊕ W2 using the last theorem from class. 3. Let V = R 3 . Consider the subspace U = {(x, y, 0) | x + y = 0}. Find a space W such that V = U ⊕ W.

$25.00 View

[SOLVED] Math 231 — hw 7

1. Determine whether the following set is a vector space. Justify your answer using theorem 1.34 from the textbook: W = {(x, y, z) | x − (y + 1) + 2(z + 1) = 1, x, y, z ∈ R}. 2. Construct an example of a vector space W with two subspaces, W1, W2, where you know W1 + W2 = W. Attempt to prove this. 3. Let V = R 4 , and define two subspaces: • V1 = {(x, y, 0, 0) | x, y ∈ R} • V2 = {(0, 0, z, w) | z, w ∈ R} Prove that V1 + V2 forms a subspace of V . 4. Prove that V1 + V2 = V in the previous problem. 5. Let V = R 2 , and define two subspaces: • V1 = {(w1, w2) | w1 + 2w2 = 0, w1, w2 ∈ R} • V2 = {(v1, v2) | v1 + v2 = 0, v1, v2 ∈ R} Prove or provide a counterexample to the statement: V1 + V2 = V .

$25.00 View