Question

Need help with this question on matlab.

Show code please!

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

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

main.m

clear all; close all; clc;

load salmon_data.csv;

t = (1:length(salmon_data)).';

% plot(t,salmon_data);
% hold on;
% Comment this before turning in.

Q = zeros(2,2);
Q(1,1) = sum(t.^2);
Q(1,2) = sum(t);
Q(2,1) = sum(t);
Q(2,2) = length(salmon_data);

R = zeros(2,1);
R(1,1) = sum(t .* salmon_data);
R(2,1) = sum(salmon_data);

P = Q\R;

save('A1.dat','Q','-ascii');
save('A2.dat','R','-ascii');
save('A3.dat','P','-ascii');

coeff_2 = polyfit(t,salmon_data,2)
coeff_5 = polyfit(t,salmon_data,5);
coeff_8 = polyfit(t,salmon_data,8);

save('A4.dat','coeff_2','-ascii');
save('A5.dat','coeff_5','-ascii');
save('A6.dat','coeff_8','-ascii');

poly_2 = polyval(coeff_2,78);
poly_5 = polyval(coeff_5,78);
poly_8 = polyval(coeff_8,78);

A7_result = [poly_2;poly_5;poly_8];

save('A7.dat','A7_result','-ascii');

coarse_time = 1:4:length(salmon_data);
coarse_time = coarse_time.';
coarse_salmon = salmon_data(1:4:length(salmon_data));

save('A8.dat','coarse_salmon','-ascii');

A9_result = interp1(coarse_time,coarse_salmon,t,'nearest');
A10_result = interp1(coarse_time,coarse_salmon,t,'linear');
A11_result = interp1(coarse_time,coarse_salmon,t,'cubic');
A12_result = interp1(coarse_time,coarse_salmon,t,'spline');

save('A9.dat','A9_result','-ascii');
save('A10.dat','A10_result','-ascii');
save('A11.dat','A11_result','-ascii');
save('A12.dat','A12_result','-ascii');

nearest_err = sqrt( 1/length(salmon_data) * sum((salmon_data - A9_result).^2) );
linear_err = sqrt(1/length(salmon_data) * sum((salmon_data - A10_result).^2));
cubic_err = sqrt(1/length(salmon_data) * sum((salmon_data - A11_result).^2));
spline_err = sqrt(1/length(salmon_data) * sum((salmon_data - A12_result).^2));

A13_result = [nearest_err;linear_err;cubic_err;spline_err];

save('A13.dat','A13_result','-ascii');
Add a comment
Know the answer?
Add Answer to:
Need help with this question on matlab. Show code please! Salmon_dat.csv 272395 286156 391573 461443 401998...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please solve using matlab and post the code used 1) Consider the following input data: x...

    Please solve using matlab and post the code used 1) Consider the following input data: x = [O 3.6 10 12 16.4 18.4 24]; y = [52 32.830 6.670 7 5.030 2*pi 8]; Use polyfit to a) determine the best polynomial fit for desired order n (1, 2, 3, 4, 5) b) determine the error between fitted and experimental data for the values of x c) determine the time to compute order range 0 to 6 using tic toc d)...

  • I want -C parts- using matlab 2. The population of the world for selected years from...

    I want -C parts- using matlab 2. The population of the world for selected years from 1750 to 2009 is given in the following table: Year Population (millions) 1750 791 1800 980 1850 1,260 1900 1.650 1950 2,520 1990 5,270 2000 6,060 2009 6,800 (a) Determine the exponential function that best fits the data. Use the function to estimate the population in 1980. Make a plot of the points and the function. (b) Curve-fit the data with a third-order polynomial....

  • Please use a MATLAB code to execute the above. 2. Use polyfit to find a 4rd...

    Please use a MATLAB code to execute the above. 2. Use polyfit to find a 4rd degree polynomial to fit the following set of data: Value =-4:1:5; Vibration = [-507.6,-261.88,-100.03,-38.08, 69, 753, 15.6, 51.8, 182, 428.97]. Plot the best fitting curve and the data points on the same figure.

  • Homework 5 (35 Points max) Please Submit all Matlab and Data files that you create for this homew...

    Homework 5 (35 Points max) Please Submit all Matlab and Data files that you create for this homework Problem 1 (max 20 Points): For the second-order drag model (see Eq.(1)), compute the velocity of a free-falling parachutist using Euler's method for the case where m80 kg and cd 0.25 kg/m. Perform the calculation from t 0 to 20 s with a step size of 1ms. Use an initial condition that the parachutist has an upward velocity of 20 m/s at...

  • Need this answered in Matlab. Show code please. Thanks. The second picture is a pseudo code...

    Need this answered in Matlab. Show code please. Thanks. The second picture is a pseudo code of how this problem should be answered. It might help. QUESTION 5: (Problem 17.13) Bessel functions often arise in advanced engineering analyses such as the study of electric fields. Here are some selected values for the zero-order Bessel function of the first kind. 1.8 2.0 2.2 2.4 2.6 J0.5815 0.5767 0.5560 0.5202 0.4708 Estimate J(2using polyfit and polyval. Also use the MATLAB's built-in function...

  • Task 2 (30 points +4 for comments): Write computer code that uses Lagrange's nterpolating Polynom...

    matlab code Task 2 (30 points +4 for comments): Write computer code that uses Lagrange's nterpolating Polynomials to fit an interpolating polynomial to the data for Task 2 in the excel file and use the polynomials to interpolate the data set and evaluate the function value at x values of 8.4, 7.6, and 6.7 What are the first through 3rd order estimations for the interpolated function value at> 8.4 and x 7.6? a) b) Extrapolate the data set to determine...

  • MATLAB HELP .. SHOW CODE PLEASE 3. Stiff ODE The following second-order ODE is considered to...

    MATLAB HELP .. SHOW CODE PLEASE 3. Stiff ODE The following second-order ODE is considered to be stiff. entre = -1001 - 1000.54 With ’ode45' command and the initial condition y(0) = 2 and y'(0) = 0, - Save the y(t) 0 <t<15) on HW8_4.dat file - Save the 0(t) (0 <t <15) on HW8_5.dat file

  • Using Matlab. The following calibration data are from a hot wire anemometer (HWA) velocity measurement system for air...

    Using Matlab. The following calibration data are from a hot wire anemometer (HWA) velocity measurement system for air flow: Air Velocity, V (m/s) HWA Output Voltage (E) 0.0 1.100 1. 1.1 1.362 2. 1.431 1.5 3. 1.487 2.0 4. 1.535 2.5 5. 1.576 6 3.0 1.647 4.0 7. 1.706 8. 5.0 1.780 9. 6.5 1.841 10. 8.0 1.910 10 11. 1.983 12. 13 13. 16 2.072 14. 20 2.159 15. 25 2.257 16. 32 2.379 17. 40 2.500 1. Perform...

  • Example 1: Least Squares Fit to a Data Set by a Linear Function. Compute the coefficients of the ...

    Example 1: Least Squares Fit to a Data Set by a Linear Function. Compute the coefficients of the best linear least-squares fit to the following data. x2.4 3.6 3.64 4.7 5.3 y| 33.8 34.7 35.5 36.0 37.5 38.1 Plot both the linear function and the data points on the same axis system Solution We can solve the problem with the following MATLAB commands x[2.4;3.6; 3.6;4.1;4.7;5.3]; y-L33.8;34.7;35.5;36.0;37.5;38.1 X [ones ( size (x)),x); % build the matrix X for linear model %...

  • Use matlab a) Create a simulated data set b) Create a set of plots to determine...

    Use matlab a) Create a simulated data set b) Create a set of plots to determine the best transformation to linearize the data c) Fit a first order polynomial (y mx + b) to the linearized data to find the constants m and b d) Reconstruct the original equation from m and b in the linear fitted polynomial e) Plot the fitted equation. Radioactive decay is modeled by the equation: rt where A the amount of mass as a function...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT