QUESTION 2: [40] The following script creates x and y vectors representing data points (you may assume x iterates from 1 to the number of points, n). x = 1:6; y [8 7.5 5 3 2.7 2]; plotline (x,y) xlabel('x'); ylabel('y'); It then passes these vectors to a function called "plotline" that produces a plot. Specifically, the function fits a straight line of the form mx + b to the points, where m is the slope of the line and b is the y-intercept. It plots these points as black *'s along with the line, extended to x = 0 so that the y- intercept can be seen. The x-axis ranges from 0 to n. The y-axis ranges from 0 to the largest y value, in either the original data points or the straight line (whichever is largest). You task is to write a local function called "plotline" that will receive x and y vectors representing the data points and achieve the above goals. "plotline" will also return the slope and y-intercept values. An output plot of the above script when executed in MATLAB is shown in Figure 3. Start with the function definition shown below: function [slope, y_intercept] = plotline (x,y) 9 8 7 6 5 > 4 3- 2 1- 0 NE 1 2 3 4 5 6 x Figure 3

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Please use MATLAB
QUESTION 2: [40]
The following script creates x and y vectors representing data points (you may assume x iterates
from 1 to the number of points, n).
x = 1:6;
y
[8 7.5 5 3 2.7 2];
plotline (x,y)
xlabel('x');
ylabel('y');
It then passes these vectors to a function called "plotline" that produces a plot. Specifically, the
function fits a straight line of the form mx + b to the points, where m is the slope of the line and b is
the y-intercept. It plots these points as black *'s along with the line, extended to x = 0 so that the y-
intercept can be seen. The x-axis ranges from 0 to n. The y-axis ranges from 0 to the largest y
value, in either the original data points or the straight line (whichever is largest).
You task is to write a local function called "plotline" that will receive x and y vectors representing
the data points and achieve the above goals. "plotline" will also return the slope and y-intercept
values. An output plot of the above script when executed in MATLAB is shown in Figure 3.
Start with the function definition shown below:
function [slope, y_intercept] = plotline (x,y)
9
8
7
6
5
>
4
3-
2
1-
0
NE
1
2
3
4
5
6
x
Figure 3
Transcribed Image Text:QUESTION 2: [40] The following script creates x and y vectors representing data points (you may assume x iterates from 1 to the number of points, n). x = 1:6; y [8 7.5 5 3 2.7 2]; plotline (x,y) xlabel('x'); ylabel('y'); It then passes these vectors to a function called "plotline" that produces a plot. Specifically, the function fits a straight line of the form mx + b to the points, where m is the slope of the line and b is the y-intercept. It plots these points as black *'s along with the line, extended to x = 0 so that the y- intercept can be seen. The x-axis ranges from 0 to n. The y-axis ranges from 0 to the largest y value, in either the original data points or the straight line (whichever is largest). You task is to write a local function called "plotline" that will receive x and y vectors representing the data points and achieve the above goals. "plotline" will also return the slope and y-intercept values. An output plot of the above script when executed in MATLAB is shown in Figure 3. Start with the function definition shown below: function [slope, y_intercept] = plotline (x,y) 9 8 7 6 5 > 4 3- 2 1- 0 NE 1 2 3 4 5 6 x Figure 3
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education