You are on page 1of 4

Panyawat

Tukaew
ECE 2010
Mailbox: 500

MATLAB PROBLEM 4

th

ECE2010 B14

Due Date Sunday Nov. 23 by 9pm


Preamble
In our fourth MATLAB problem, we will investigate some basic operations with solar
electric power (distributed power, total power).
From the software point of view, we will learn how to work with
A. MATLAB for loops;
B. Matrixes (2D arrays) and;
C. 2D Contour plots.
Along with the traditional for loops for matrices and vectors, MATLAB supports many
symbolic matrix/vector operations; one of which is illustrated in the present problem. Those
operations are much faster than the for loops in MATLAB.
Problem statement
To date, the average electricity consumption of the USA is approximately 51011 W=500
Gigawatts. A beginner electrical engineer estimates the size of a square area in the state of
New Mexico to be covered with c-Si solar cells or with a-Si solar cells in order to fulfill this
need.
The engineer intends to check all possible square areas from 1 to 150 miles in width, as well
as all possible panel efficiencies from 1 to 20%. After that he/she would like to create a
contour plot in order to observe how does the required area increase/decrease depending on
the available efficiency.
An older colleague from the same company has already started a MATLAB script for that
purpose, which is given below. However, this colleague made one serious theoretical mistake
(related to average daily solar radiation), and two programming mistakes:
clear all;
close all;
%-------------------------------------------------------%
Vector of available area widths (a 1D array of numbers)
Wmiles = [1:1:150];
%
width of the square area in miles (vector or 1D array)
Wmeters = Wmiles*1609; %
width of the square area in meters (vector or 1D array)
A = Wmeters.*Wmeters; %
area in m^2 (vector or 1D array); note element-by-element
%
vector multiplication!
%-------------------------------------------------------%
Vector of available array efficiencies (a 1D array of numbers)
E
= [1:1:20]];
%
efficiency percentage (vector or 1D array)
%-------------------------------------------------------%
Matrix of all available total output powers of the array (a 2D array of numbers)
p
= 1000;
%
average daily solar radiation in W per m^2 (scalar)
for i = 1:length(A)
%
index i corresponds to different areas A
for j = 1:length(E)
%
index j corresponds to different efficiencies E
P(i,j) = p*A(i)*E(k)*0.01; %total average daily power (2D matrix)
end
end
%-------------------------------------------------------%
"Plot" the matrix - a contour plot of all available total output powers
v
= [2 10 50 100 300 500 1000]; %
create contour plot levels in GWatts
C = contourf(P*1e-9, v);
%
create contour plot of output powers in GWatts
colormap(summer);
clabel(C, 'FontSize', 11, 'Color', 'r'); %
be fancy (do not have to)
grid on; xlabel('Efficiency, %'); ylabel('Area size, m^2');

Panyawat Tukaew
ECE 2010
Mailbox: 500

Your task:
1. Create an empty MATLAB script, copy and paste the above text over there. Save the
script. Give your own script name. Note that all comments are marked green.
2. Run the script. You will see error message(s).
3. Find and fix all bugs in the above script. Remember: all programming errors are
reported
in
red
in
MATLAB
Command
Window.
Example:

You could click on the error message; it will bring you to the line with an error.
You may also want to use Fig. 1 and double check the number(s) used in the initial
script. Note that 1kWh/m2/day = 10001/24 W/m2= 41.67 W/m2. The state of New
Mexico has about 6.5kWh/m2/day.
4. Properly label axes, insert the grid, and insert the title. The x-axis should be Solar
panel efficiency percentage, E; the y-axis should be the Width of the square
area in miles, W.
5. Include the corrected MATLAB script, and the corresponding contour plot into your
MATLAB report.

Fig. A1. A map of average daily solar radiation from National Renewable Energy Laboratory, U.S.

Panyawat Tukaew
ECE 2010
Mailbox: 500

Questions

clear all;
close all;
%-------------------------------------------------------% Vector of available area widths (a 1D array of numbers)
Wmiles = [1:1:150]; % width of the square area in miles (vector or 1D array)
Wmeters = Wmiles*1609; % width of the square area in meters (vector or 1D array)
A = Wmeters.*Wmeters; % area in m^2 (vector or 1D array); note element-by-element
% vector multiplication!
%-------------------------------------------------------% Vector of available array efficiencies (a 1D array of numbers)
E = [1:1:20]; % efficiency percentage (vector or 1D array)
%-------------------------------------------------------% Matrix of all available total output powers of the array (a 2D array of numbers)
p = 4000; % average daily solar radiation in W per m^2 (scalar)
for i = 1:length(A) % index i corresponds to different areas A
for j = 1:length(E) % index j corresponds to different efficiencies E
P(i,j) = p*A(i)*E(j)*0.01; %total average daily power (2D matrix)
end
end
%-------------------------------------------------------% "Plot" the matrix - a contour plot of all available total output powers
v = [2 10 50 100 300 500 1000]; % create contour plot levels in GWatts
C = contourf(P*1e-9, v); % create contour plot of output powers in GWatts
colormap(summer);
3

Panyawat Tukaew
ECE 2010
Mailbox: 500

clabel(C, 'FontSize', 11, 'Color', 'r'); % be fancy (do not have to)
grid on; xlabel('Solar panel efficiency percentage, E'); ylabel('Width of the square area in
miles, W'); title('Area vs. Efficiency Graph');
1. What is the size of array A? To answer this question type size(A) in MATLAB
Command Window and hit ENTER.
a. Array A is 1 by 15
2. What is the size of array E?
a. Array E is 1 by 20
3. What is the size of array P?
a. Array P is 150 by 20
4. What happens if you replace two nested for loops by one short line of the code:
P = p*kron(A', E)*0.01;

Here, the prime symbol denotes the transpose operation, i.e. the conversion from a
row to a column; kron stands for a tensor product of two vectors (studied in math
classes), which gives us a matrix.
Does your result change?
No, the result doesnt change.
5. Based on your contour plot please answer the following question: what is the
minimum possible square area (and its width in miles) that gives us the average
electric output of the array greater than or equal to the current USA electric
consumption of 51011 W=500 Gigawatts at the solar panel efficiency of 15%?
25 square miles. 5 miles by 5 miles.
Your report should include:
A.
B.
C.
D.

Name and ECE mailbox.


The corrected MATLAB script.
The contour plot.
Answers to questions 1 through 5.

There is a MATLAB help session this coming Sunday from 7 PM to 9 PM in AK317a


(ECE Dept).
Also you can utilize the discussion board on MyWPI or send an email to our dedicated TAs,
Ali or Janakinadh:
Ali: azakhtar@wpi.edu
Janakinadh: jyanamadala@wpi.edu

You might also like