I am not sure how to even get started. I am supposed to use feof to open the file but I cannot get it to work. Can anyone show me how to use feof? Thanks
Show older comments
Before you start writing your program:
Read all of these instructions carefully.
Using previous assignments as a guide determine the following for this problem.
1. Problem Constants: (with units, as needed)
2. Problem Inputs: (with units, as needed)
3. Problem Outputs: (with units, as needed)
4. Other variables: (with units, as needed)
5. Equations
6. Algorithm: Copy and paste your algorithm as comments in your program.
Include 1-6 from above in the comments at the top of your Lab07.m file.
Program: Lab07.m
Edwin Hubble used the Mount Wilson Observatory telescopes to measure features of nebulae outside the Milky Way. He found that there is a relationship between a nebula’s distance from earth and the velocity with which it was traveling from the earth. Hubble’s initial data on 24 nebula is presented in Table 1 in the problem scenario.
The relationship between distance and velocity led scientists to propose that the universe came into being with a Big Bang, a long time ago. If material scattered from the point of the Big Bang traveling at a constant velocity, the distance traveled can be determined.
Using Hubble’s data, find the linear equation that estimates the relationship between the velocity and distance readings. Display the data in a table and graph.
General Instructions:
Insert comments at the top and throughout each file
o Include the follow comments at the beginning of this (and ALL) files.
your name Grade of zero for files with incorrect author name
assignment number Zero points for comments if no collaboration statement
date you completed the assignment
statement(s) about collaboration
a short narrative about what the file does
o Use the algorithm as comments throughout each file.
o Add section headers. See Standards for Documentation of MATLAB programs on Resources page on Canvas.
Variables:
o Use ALL CAPS for constants variable names.
o Start other variables with lower case.
o Use descriptive variable names.
o Use variables for data values. Note: zero(0), one (1), and column index numbers are allowed.
Code clarity:
o Indent blocks as needed. In editor, select ALL, right-click, Smart Indent in the pop-up menu.
o Divide you solution program code into sections as noted in the algorithm.
o Use section comments as well as the algorithm step comments.
o Use blank lines as needed to group statements.
Data file:
o Check for good open. Display system message and end program there is a problem.
o Use fscanf() to read one row at a time.
o Read Hubble’s data from hubbleData.txt. Read until the end-of-file is found
o You know that there are five columns, but you will need to count the rows of data read
o There are five columns of data in the data file. You will read all but only use the velocity and distance in the program computations. Compare hubbleData.txt with the table in the scenario for the column content.
o Velocity will be the independent variable(x) variable and distance dependent variable(y).
o You know that there are five columns, but you will need a row counter for the row index as the data is read.
Computation
o Use the given formula to compute the slope and intercept for the given data.
o Create the regression equation that estimates the relationship between the velocity and distance readings.
COMP1200M – Spring 2013 – Lab07 – p. 2 of 2
Output
o NO extra output, i.e. use semicolon as needed and use “clc, clear all” to remove previous output.
o Label output using the fprintf()function.
Format the output decimal places as shown in the sample below.
Include units, if applicable.
o Columns of numbers right-aligned.
o Print the velocities and distances in a two columns with a title and column headings
o Print slope and y-intercept in the form of a linear equation.
o Display the data in a scatter plot and line of the graph a linear equation
Use the code below to draw a scatter plot for the data pairs and draw a line of the linear equation
o Replace velocity column and distance column with matrix columns where you saved velocity and distance.
o “hold on” allows the line plot to be drawn in the same figure as the scatter.
o Create a vector xVelocity starting with minimum value of Hubble’s velocity and ending with the maximum value of Hubble’s velocity.
o Compute the values for yDistance using the linear equation that you created.
% create a scatter plot of the velocity and distance data
% plot the line created by your linear equation
scatter( velocity column, distance column )
hold on % allows both graphs in the same figure
xVelocity = _______________________________;
yDistance = _______________________________;
plot(xVelocity,yDistance)
Sample Input/Output:
NEBULA INPUT DATA
VELOCITY DISTANCE
km/sec 106 parsecs
170 0.032
290 0.034
-130 0.214
. . .
500 2.000
850 2.000
800 2.000
1090 2.000
LINEAR EQUATION: distance = 0.0014 * velocity + 0.399
Submit via Canvas:
Lab07.m MATLAB script file
Accepted Answer
More Answers (1)
Kyle
on 21 Mar 2013
0 votes
have you gotten started yet? I have the same assignment and i have no idea where to start or what to do
6 Comments
anthony
on 22 Mar 2013
Well, you have a file with data; how does it look like? Copy/paste part of it as a comment here, caring for the formatting to be good enough so we can see the structure without having to spend time deciphering, and tell us what you tried to do so far for reading it.
anthony
on 22 Mar 2013
anthony
on 22 Mar 2013
anthony
on 22 Mar 2013
Cedric
on 22 Mar 2013
I'll go on below my answer, further up in the page.
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!