Question
Need help with this question on matlab.
Show code please!
Salmon_dat.csv
272395
286156
391573
461443
401998
313120
240763
297488
446152
480276
420555
277697
357375
331788
420879
332479
320947
359853
300917
403286
416419
345028
256049
281980
286625
278560
344422
317956
219688
259337
208197
189419
272884
360673
248860
306981
401711
867728
870035
921314
846026
570413
493708
275954
518942
480284
809799
677171
589937
1129664
1152642
Exercise 1: Salmon Runs Download the file salmon-dat.csv included with the homework. This file con- tains the annual Chinook salmon counts taken at Bonneville on the Columbia river from the years 1938 to 2014 (www.cbr.washington.edu). You can load this file into MATLAB using >>load salmon data.csv. Do not upload this file to Scorelator, your code will be tested using the counts for another species of salmon (a) You should begin by creating a time vector >t-(1 length(salmon data)).' and plotting the salmon counts against the year in which they were taken (plotting usually helps you get a better understanding of the data), but make sure to comment out the plot before submitting. Note that we have let 1938 be represented by year 1 (making 2014 year 77), continue with this convention in the rest of the problem. In the video lectures, you learned that the following matrix equations could be used to determine the coefficients of a linear best-fit k tkyk where yk is the k-th index of the salmon count data. The solution provides A and B such that y-At +B is the RMS best-fit lne. Compute the Q, R. and P matrices and concatenate them in that order to form a 2x 4 matrix. Save the result in A1.dat. You can confirm that your A and B are correct by finding a first order fit using polyfit (b) Use polyfit to find the best-fit polynomials of order 2, 5, and 8, and save these coefficients in A2.dat, A3.dat, and A4.dat, respectively. You should plot each of these best-fits, but make sure to comment out the plot before submitting. (c) Using each polynomial fit from (b), predict the salmon counts in 2015. Save the predictions from each polynomial fit in a column vector with 3 elements in A5.dat. If you are curious, look at the website provided above to see if the predictions were accurate! (d) We will now use this data to study interpolations. Create coarse vectors of time and the salmon data which contain the first element and every fourth subsequent element. For example, the coarse time vector would begin with [1; 5; 9; 13; ...1. Save the coarse salmon data as A6.dat (e) Now, interpolate this coarse data onto the original time vector using each of the following methods: nearest neighbor, linear, cubic, and spline. Compute the interpolated salmon count values for these methods as column vectors, concatenate them in that order in a matrix length(salmon.data)x 4 ma trix, and save the result in A7.dat
Explanation / Answer
main.m