Home / Expert Answers / Computer Science / matlab-find-line-best-fit-of-co2-data-guessing-and-its-minima-nbsp-the-file-c02-data-csv-contains-pa258

(Solved): MATLAB Find line best fit of CO2 data guessing and its minima  The file C02_data. csv contains ...



MATLAB Find line best fit of CO2 data guessing and its minima The file C02_data. csv contains monthly averages of atmospheric \( \mathrm{CO}_{2} \) (in parts per million) measured at the (a) Find a best fit line \( y=m t+b \) for this data. Store the coefficients in a \( 1 \times 2 \) row vector (in the same or

The file C02_data. csv contains monthly averages of atmospheric \( \mathrm{CO}_{2} \) (in parts per million) measured at the Mauna Loa observatory in Hawaii. (You can find this data, along with much more information about the measurements, here.) You can load this data with the code data = readmatrix('C02_data.csv') \( \mathrm{t}=\operatorname{data}(1,:) \) \( \operatorname{co} 2=\operatorname{data}(2,:) \) (This code assumes that the file C02_data.csv is in the same directory as your code. You do not need to upload the .esv file to gradescope, but you do need to include these lines of code in your script.) This will create two variables: co2 contains atmospheric \( \mathrm{CO}_{2} \) at each month and \( t \) contains time measured in years since the beginning of 1958 . The first entry is from March, 1958 and the last entry is from September, 2022. The \( \mathrm{CO}_{2} \) concentration has risen steadily over the last 64 years, but also undergoes distinct seasonal oscillations: (a) Find a best fit line \( y=m t+b \) for this data. Store the coefficients in a \( 1 \times 2 \) row vector (in the same order as given by polyfit) named A10. Find the RMS error of this fit and store it in a variable named A11. (b) It looks like the data might be growing roughly exponentially. This means that we should try to find a best fit curve of the form \[ y=a e^{r t}+b \] Use fminsearch to find the values of \( a, r \) and \( b \) that minimize the RMS error between this curve and our data. Use an initial guess of \( a=30, r=0.03 \) and \( b=300 \). Store your answers in a \( 1 \times 3 \) row vector \( [a, r, b] \) named A12. Find the RMS error of this fit and store it in a variable named A13. (c) You should find that the best fit exponential curve captures the overall trend of the data well, but that it does not do a good job of capturing scasonal oscillations. To fix this, we can try to find a best fit curve of the form \[ f(t)=a e^{r t}+b+A \sin (B(t-C)) \] Use fminsearch to find the values of \( a, r, b, A, B \) and \( C \) that minimize the RMS error between this curve and our data. Since this model is similar to the one from the last part, it seems likely that \( a, r \) and \( b \) will be similar to the best fit values we found previously. Because of this, we will use the exact values of \( a \), \( b \) and \( r \) that you calculated in \( \mathrm{A} 12 \) as initial guesses in this step. Use \( A=-5 \), \( B=5 \) and \( C=0.5 \) as initial gucsses for the other variables. Store your answers in a \( 1 \times 6 \) row vector \( [a, r, b, A, B, C] \) named A14. Find the RMS error of this fit and store it in a variable named \( \mathrm{A} 15 \). Note: This last part is a fairly difficult optimization problem, so you will need to let fminsearch run for more steps than normal. You can do so with the code options \( = \) optimset ('MaxFunEvals', 100000); fminsearch(your_function, your_guess, options) where your_function and your_guess are the function and guess that you would normally supply to fminsearch. 3


We have an Answer from Expert

View Expert Answer

Expert Answer


Below find the code !! clc clear t = 0:5:40; theta = [23.2
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe