What values do you obtain for the slope and y-intercept

Assignment Help MATLAB Programming
Reference no: EM131303334

Instructions: For each of the following exercise, create an M-file to store the MATLAB commands. Copy and paste the M-file into a text document. Include in the text document the pictures produced by MATLAB. Resize and crop the pictures so that they do not take up too much space. If the question requires written answers, include them in the text file in the appropriate location. Make sure you clearly label and separate all the Exercises. Preview the document before printing and remove unnecessary page breaks and blank spaces.

1. Consider a set of data points (1, y1), (2, y2), ...(100, y100) where the y's are random numbers with a normal distribution with mean 0 and variance 1 (note that this implies that the probability of the y- values being less than zero is the same as the probability of being greater than zero).

(a) Based on the distribution of the points, what do you expect is the best straight-line model that can be fit to the data?

(b) To confirm numerically your answer to part (a), generate the data as follows:

x = [1:1:100]';        %note the prime

y = randn(size(x));   % a column vector of 100 standard normal values.

Plot the values as dots with the command plot(x,y,'.'). Follow Example 1 to find the best linear fit using MATLAB. Answer the following questions:

(i) What values do you obtain for the slope and y-intercept? Give the values in scientific notation with five digits of accuracy (use format short e).

Plot the linear fit together with the points (use q = x;)

(ii) Do the values of the slope and y-intercept confirm your answer to part (a)? Explain.

2. Download the file co2.dat from the web page. This file contains two columns of numbers: the year from 1959 to 2012 and the average annual carbon dioxide concentration in the atmosphere (in parts per million), as measured at the Mauna Loa observatory in Hawaii. The data come from the Earth Systems Research Laboratory (Global Monitoring Division) of the National Oceanic and Atmospheric Administration (which is the government agency charged with developing weather and climate forecast models; if you are interested in additional information and data set you can visit https://www.esrl.noaa.gov/gmd/ccgg/trends ). The estimated standard error in the observations is 0.12 ppm.

Save the file in the MATLAB working directory. Then load it with

dat = load('co2.dat');

Note: if you do not save the file in your working directory, you need to include the whole path to load it into MATLAB. For instance, if you saved your file in the C:\tmp directory you can load it by entering load('C:\temp\co2.dat').

This creates the 49 × 2 array dat whose first column is the year and whose second column is the CO2 concentration.

You may find it convenient to create two separate data vectors, as follows:

year = dat(:,1);
conc= dat(:,2);

Plot the data with

plot(year,conc,'o')

(a) Follow Example 1 to compute the best-fit line for these data. What are the coefficients c1 and c2? Give the values with five digits of accuracy. Plot the line in black ( use q = year;), together with the original data. Use 'linewidth',2 and axis tight in your plot.

(b) Find the best-fit quadratic polynomial to the CO2 data (make sure you change appropriately the matrix X). What are the coefficients c1, c2 and c3? Give the values with five digits of accuracy. Plot the fitted curve in red (use 'linewidth' ,2) together with the data points and the linear fit from part (a). Add a legend to the graph.

3. Among the important inputs in weather-forecasting models are data sets consisting of temperature values at various parts of the atmosphere. These values are either measured directly with the use of weather balloons or inferred from remote soundings taken by weather satellites. A typical set of RAOB (weather balloon) data is given next. The temperature T in Kelvins may be considered as a function of p, the atmospheric pressure measured in decibars. Pressure in the range from 1 to 3 decibars correspond to the top of the atmosphere, and those in the range from 9 to 10 decibars correspond to the lower part of the atmosphere.

p

1

2

3

4

5

6

7

8

9

10

T

222

227

223

233

244

253

260

266

270

266

Enter the pressure values as a column vector p (use the colon : operator), and enter the temperature values as a column vector T.
The goal of this problem is to find the cubic polynomial y = c1 + c2x + c3x2 + c4x3 that gives the best least square fit to the data.

(a) Follow Example 1 to find the coefficients of the best cubic fit (make sure you appropriately modify the matrix X).

Plot the data together with the cubic fit. Make sure you define your vector q so that the graph of the cubic is nice and smooth.

(b) Let X be the matrix you used in part (a). Here is an easier way to evaluate and plot the cubic polynomial:

c = X\T

c = c([4:-1:1]); q = 1:0.1:10;

z = polyval(c,q); figure plot(q,z,p,T,'o');

How do the values of c compare to the ones you found in part (a)?

How does the plot compare to the one you found in part (a)?

Note that the system Xc = T is overdetermined. In this case, the "\" command finds the least-squares solution to the system. In fact, for overdetermined systems, the "\" command is equivalent to solving the Normal Equations using the Cholesky decomposition, just like you did in the previous problems. Thus the vector c = X\T is the same one you found in part (a) by solving the normal equations.

The command polyval(c,q) evaluates the polynomial with coefficients given by the vector c in decreasing powers of q. Because the powers are decreasing we had to rearrange the entries in c using the command c = c([4:-1:1]);. Type help polyval to learn more.

Attachment:- Least Squares.pdf

Reference no: EM131303334

Questions Cloud

What happens to your average cost rational function : What happens to your average cost rational function when x gets very large? Explain your answer. How many items must be produced before the average cost is 1.5 times your chosen value of m?
How long have the had the specific disease : FCS 1253:How long have the had the specific disease / condition?What medications do they currently take ?Could it have been prevented by dietary control?Does controlling their diet now make a difference in their current health status and quality of l..
Rule of man dominates the legal system : What are the pros and cons to living in a society where the rule of man dominates the legal system? Would the rule of man be a better system than the rule of law in your opinion?
Where marginal cost and marginal revenue are equal : If so, how can that be done? If the concept is applied, how confident should we be that the firm will achieve the point where marginal cost and marginal revenue are equal
What values do you obtain for the slope and y-intercept : What values do you obtain for the slope and y-intercept? Give the values in scientific notation with five digits of accuracy (use format short e) -
Economic growth and development : In the early modern period in Western Europe 1500-1750, France was big, Spain wasrich, The Netherlands was efficient, and China and India with their large populationsdominated world economic production. What then was Britain's competitive advantag..
What does white-collar crime reveal about power and deviance : What does white-collar crime (found in the examples of Enron and the 2008 financial crisis) reveal about power and deviance? How does this relate to other forms of criminal behaviors and the punishment established?
Calculate the expected return and variance : Calculate the expected return and variance of portfolios invested in T-bills and the S&P 500 index with weights as follows: Calculate the utility levels of each portfolio of Question 1 for an investor with A = 2. What do you conclude
What is the aggregate level of deposits in the economy : a. What is the aggregate level of deposits in the economy? b. Write down the money market-clearing condition. Compute the equilibrium price level. c. What is the aggregate level of real money balances in the economy? d. Compute the money multiplier.

Reviews

len1303334

12/6/2016 8:02:37 AM

For each of the following exercise, create an M-file to store the MATLAB commands. Copy and paste the M-file into a text document. Include in the text document the pictures produced by MATLAB. Resize and crop the pictures so that they do not take up too much space. If the question requires written answers, include them in the text file in the appropriate location. Make sure you clearly label and separate all the Exercises. Preview the document before printing and remove unnecessary page breaks and blank spaces.

Write a Review

MATLAB Programming Questions & Answers

  Finite difference method

Use the finite difference method to calculate the temperature at the point specified since it is easier.

  Determine the necessary shell temperature

In a shell-and-tube heat exchanger, one fluid passes through a central tube while another fluid flows through an outer shell in the opposite direction. The purpose is to heat the fluid passing through the central tube.

  Find the integral of a function at an arbitrary location

Write a Matlab function to perform numerical integration of a set of evenly spaced data points using the trapezoidal rule

  Compute the speed of single-stage planetary gear train

Write a MATLAB function [speed] = planetary (N, emesh, first, last, arm) that computes the speed of a given link in a single-stage planetary gear train.

  Calculate and plot the error in the numerical derivative

Write a program to calculate and plot the error in the numerical estimate of the derivative.

  Create the graph using matlab functions

Create the graph, which contains a piecewise function where a line exists in the first interval, a parabola in the second interval, and the sine function in the third interval.

  Develop a simulation program

Develop a simulation program

  Create a vector in matlab

Create a three dimensional diagram of function.

  Open a named pipe and to read data from the pipe

Open a named pipe and to read data from the pipe in matlab

  Write the commands that will create the matrix

Write the commands that will create the matrix.

  Lagrange interpolating polynomial of degree

Lagrange interpolating polynomial of degree

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd