Arizona State University MathLab Worksheet

User Generated

PbbxvrZbafgreRyzb

Programming

Arizona State University

Description

Need help with creating the project below using Mathlab.

Unformatted Attachment Preview

State Dec 2020 rate Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina North Dakota Ohio Oklahoma Oregon 11.39 21.93 12.18 9.87 20.45 12.14 20.39 12.51 11.86 10.8 29.14 9.92 12.32 12.69 11.31 12.22 10.53 9.54 16.51 12.73 21.54 16.47 12.87 11.25 9.3 11.02 10.13 11.2 18.74 15.99 12.27 18.23 10.6 9.39 11.8 8.88 10.89 Avg. montly usage 1,201 555 1,014 1,118 532 682 689 950 1,108 1,121 525 949 709 960 867 891 1,112 1,232 562 975 574 637 759 1,206 1,058 857 1,004 890 599 663 640 577 1,079 1,109 874 1,116 911 Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming United States 13.15 22.59 11.78 11.39 10.41 11.87 10.19 19.04 11.21 9.77 11.41 14.52 10.66 12.8 837 560 1,114 1,044 1,217 1,140 727 549 1,122 973 1,084 674 864 887 San Diego State University – Department of Electrical and Computer Engineering EE300 - Computational and Statistical Methods of Electrical Engineers Spring 2022 - MATLAB Project The attached Excel file contains a data set on electricity usage across 50 U.S. states in the month of Dec 2020. We want to examine if the electricity charge rate per kWh has correlation with the electricity usage. In practice, there are many other factors that affect the energy usage. We’re only concerned about the electricity charge per kWh here. You should define x as a vector recording the data for the RATE per kWh and y as a vector recording the average number of kWh USAGE across the 50 states. You can save your data into a ‘mat’ file by the MATLAB function save(’data.mat’,’x’,’y’). Next time when you retrieve the data, use the MATLAB function load(’data.mat’). Perform the following tasks: 1. (2pt) Find the (sample) means of the RATE and the USAGE and store them as mX and mY . • (1pt) You may wish to try the MATLAB functions mean(x) and mean(y). • (1pt) Write your own function my mean(x) that takes input as a data vector x and returns its mean mX . This function should provide the following result mX = N 1 X xi N i=1 where N is the length of the data vector x and xi is its ith element. Compare the result you get from my mean(x) and my mean(y) with mean(x) and mean(y) 2. (2pt) Find the (sample) standard deviation of the RATE and the USAGE and store them as stdX and stdY . • (1pt) You may wish to try the MATLAB functions std(x) and std(y). • (1pt) Write your own function my std(x) that takes input as a data vector x and returns its standard deviation mX . This function should provide the following result v u N u 1 X stdX = t (xi − my mean(x))2 . N − 1 i=1 You need to use your own function my mean(x) to get the mean of x. Compare the result you get from my std(x) and my std(y) with std(x) and std(y). 3. (2pt) Determine the median of the RATEs and store it as medianX • (1pt) You may wish to try the MATLAB function median(x). • (1pt) Write your own function my median(x) that takes input as a data vector x and returns its median medianX . You must sort the data vector x in an ascending order into xa first, and then proceed to find the median (the mid point). You must write a script that is usable for both odd and even number of samples. Print your result and compare it with the result obtained from the MATLAB function median(x). 4. (1pt) Illustrate the data in the table using a scatter plot with the horizontal axis representing the RATE and the vertical axis representing the USAGE. From the plot, determine whether the RATE and the USAGE have positive correlation, negative correlation or no correlation. Suggestion: You may wish to try the MATLAB function scatter(x, y). Attach the plot in your report. 5. (1pt) Find the sample covariance of the RATE and the USAGE and store it as covXY . Suggestion: You may wish to try the MATLAB command N/(N − 1) ∗ mean((x − mx). ∗ (y − my)). 1 6. (2pt) Find the correlation coefficient from the sample covariance and the standard deviations of the RATE and the USAGE. Print the obtained correlation coefficient, and determine if the calculation confirms with your observation from the scatter plot. Please turn in your MATLAB script in one section and the results/plots in another section. Attach all in one document and upload to the Project submission link on Blackboard. Deadline: Sunday May 15 at 11:59 PM. No late submission is allowed. 2
Purchase answer to see full attachment
Explanation & Answer:
full script
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Please view explanation and answer below.

Section 1: MATLAB code
The data is extracted from the excel file and stored in MATLAB using the following code:
% Clear the workspace and the command window before execution of the code
clear; clc
% Load the data stored in the excel
excel_data = xlsread('electricity_usage_us_states.xlsx');
% First column is the electricity rate
rate = excel_data(1:50,1);
% Second column is the average electricity consumption
usage = excel_data(1:50,2);
% Save the data
save('rate.mat');
save('usage.mat');

Part 1:
The mean of the rate and usage is obtained using the in-build function and my_mean function:
% Clear the workspace and the command window before execution of the code
clear; clc
% Load the data into the workspace
load('rate.mat')
load('usage.mat')
% Calculate the mean using MATLAB function
mx = mean(rate);% Mean rate
my = mean(usage);% Mean usage
% Calcuating the mean using my own mean function
mx_myrate = my_mean(rate);% Mean rate
my_myusage = my_mean(usage);% Mean usage
% Print the result
fprintf('Mean of the rate using inbuild mean function is $%0.4f/kWh\n',mx)
fprintf('Mean of the rate using my_mean function is $%0.4f/kWh\n',mx_myrate)
fprintf('Mean of the usage using inbuild mean function is %0.4f kWh\n',my)
fprintf('Mean of the usage using my_mean function is %0.4f kWh\n...


Anonymous
Excellent resource! Really helped me get the gist of things.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags