
To write:
A

Answer to Problem 27E
Solution:
The file is,
%MATLAB code to load the data and create a data structure file.
%structure file.
stormdata = [321 2.4 1.5]
save stormdata.dat stormdata -ascii
stormdata = [111 3.3 12.1]
save stormdata.dat stormdata -ascii
clear
load stormdata.dat
%end of function file
%The function file should be placed in the same folder
The function file is,
%MATLAB code to print a table between stormdatavector and intensity.
%function file.
function tableprint(stormdatavector, intensity)
for i = 1:length(stormdatavector)
fprintf('%20.1f\t%20.1f\t%20.1f|t%20f\n', stormdatavector(i).locationcode, stormdatavector(i).rainfallamount, stormdatavector(i).stormduration, intensity(i))
end
end
%end of function file
%The function file should be placed in the same folder.
The function file is,
%MATLAB code to calculate the average intensity.
%function file.
function avgintensity(intensity)
intensitysum = 0;
for i = 1:length(intensity)
intensitysum = intensitysum + intensity(i);
end
avgintensity = intensitysum/length(intensity);
fprintf('Average intensity of storm is %f\n', avgintensity)
end
%end of function file
%The function file should be placed in the same folder.
The function file is,
%MATLAB code to find the information about mostintensestorm.
%function file.
function mostintensestorm(stormvector, intensity)
for i = 1:length(intensity)
for j = i + 1:length(intensity)
if intensity(i)>intensity(j)
temp = intensity(i);
intensity(i) = intensity (j);
intensity(j) = temp;
end
end
end
fprintf('the information of most intense storm is:%f\n', intensity(length(intensity)))
tempindex = index(stormvector, intensity);
fprintf('the index of most intense storm is:%d\n', tempindex);
fprintf('%20s|t%20s\t%20s\t%20s\n','location code','rainfall amount','storm duration','intensities')
fprintf('%20.1f\t%20.1f\t%20.1f\t%20f\n', stormvector(tempindex).locationcode, stormvector(tempindex).rainfallamount, stormvector(tempindex).stormduration, intensity(length(intensity)))
end
function index = index(stormvector, intensity)
for i = 1:length(stormvector)
if intensity(length(intensity)) ==stormvector(i).rainfallamount/stormvector(i).stormduration
index = i;
break;
end
end
end
%end of function file
%The function file should be placed in the same folder.
The function file is,
%MATLAB code to find the output.
%function file.
fprintf('%20s\t%20s\t%20s\t%20s\n','location code','rainfall amount','storm duration','intensities')
for i = 1:size(stormdata, 1)
for j = 1:length(stormdata(i))
stormvector(i) = struct('locationcode', stormdata(i, j),'rainfallamount', stormdata(i, j+1),'stormduration', stormdata(i, j+2));
intensity(i) = stormvector(i).rainfallamount/stormvector(i).stormduration;
end
end
tableprint(stormvector, intensity)
avgintensity(intensity)
mostintensestorm(stormvector, intensity)
%end of function file
%The function file should be placed in the same folder.
Explanation of Solution
The output is,
The average intensity is,
The location code is,
The rainfall amount is,
MATLAB Code:
clc
clear all
close all
%MATLAB code to load the data and create a data structure file.
%structure file.
stormdata = [321 2.4 1.5]
save stormdata.dat stormdata -ascii
stormdata = [111 3.3 12.1]
save stormdata.dat stormdata -ascii
clear
load stormdata.dat
%end of structure file
%The file should be placed in the same folder
output;
%The function file should be placed in the same folder
%MATLAB code to print a table between stormdatavector and intensity.
%function file.
function tableprint(stormdatavector, intensity)
for i = 1:length(stormdatavector)
fprintf('%20.1f\t%20.1f\t%20.1f|t%20f\n', stormdatavector(i).locationcode, stormdatavector(i).rainfallamount, stormdatavector(i).stormduration, intensity(i))
end
end
%end of function file
%The function file should be placed in the same folder.
%MATLAB code to calculate the average intensity.
%function file.
function avgintensity(intensity)
intensitysum = 0;
for i = 1:length(intensity)
intensitysum = intensitysum + intensity(i);
end
avgintensity = intensitysum/length(intensity);
fprintf('Average intensity of storm is %f\n', avgintensity)
end
%end of function file
%The function file should be placed in the same folder.
%MATLAB code to find the information about mostintensestorm.
%function file.
function mostintensestorm(stormvector, intensity)
for i = 1:length(intensity)
for j = i + 1:length(intensity)
if intensity(i)>intensity(j)
temp = intensity(i);
intensity(i) = intensity (j);
intensity(j) = temp;
end
end
end
fprintf('the information of most intense storm is:%f\n', intensity(length(intensity)))
tempindex = index(stormvector, intensity);
fprintf('the index of most intense storm is:%d\n', tempindex);
fprintf('%20s|t%20s\t%20s\t%20s\n','location code','rainfall amount','storm duration','intensities')
fprintf('%20.1f\t%20.1f\t%20.1f\t%20f\n', stormvector(tempindex).locationcode, stormvector(tempindex).rainfallamount, stormvector(tempindex).stormduration, intensity(length(intensity)))
end
function index = index(stormvector, intensity)
for i = 1:length(stormvector)
if intensity(length(intensity)) ==stormvector(i).rainfallamount/stormvector(i).stormduration
index = i;
break;
end
end
end
%end of function file
%The function file should be placed in the same folder.
%MATLAB code to find the output.
%function file.
fprintf('%20s\t%20s\t%20s\t%20s\n','location code','rainfall amount','storm duration','intensities')
for i = 1:size(stormdata, 1)
for j = 1:length(stormdata(i))
stormvector(i) = struct('locationcode', stormdata(i, j),'rainfallamount', stormdata(i, j+1),'stormduration', stormdata(i, j+2));
intensity(i) = stormvector(i).rainfallamount/stormvector(i).stormduration;
end
end
tableprint(stormvector, intensity)
avgintensity(intensity)
mostintensestorm(stormvector, intensity)
%end of function file
%The function file should be placed in the same folder.
Save the MATLAB script with name, chapter8_54793_8_27E.m and function files with names tableprint.m, avgintensity.m, mostintensestorm.m and output.m in the current folder. Execute the functions by typing the functions name at the command window to generate output.
Result:
The result is,
Therefore, the result is stated above.
Want to see more full solutions like this?
Chapter 8 Solutions
Matlab, Fourth Edition: A Practical Introduction to Programming and Problem Solving
- Theorem 1.2 (1) Suppose that P(|X|≤b) = 1 for some b > 0, that EX = 0, and set Var X = 0². Then, for 0 0, P(X > x) ≤e-x+1²² P(|X|>x) ≤2e-1x+1²² (ii) Let X1, X2...., Xn be independent random variables with mean 0, suppose that P(X ≤b) = 1 for all k, and set oσ = Var X. Then, for x > 0. and 0x) ≤2 exp Σ k=1 (iii) If, in addition, X1, X2, X, are identically distributed, then P(S|x) ≤2 expl-tx+nt²o).arrow_forwardTheorem 5.1 (Jensen's inequality) state without proof the Jensen's Ineg. Let X be a random variable, g a convex function, and suppose that X and g(X) are integrable. Then g(EX) < Eg(X).arrow_forwardCan social media mistakes hurt your chances of finding a job? According to a survey of 1,000 hiring managers across many different industries, 76% claim that they use social media sites to research prospective candidates for any job. Calculate the probabilities of the following events. (Round your answers to three decimal places.) answer parts a-c. a) Out of 30 job listings, at least 19 will conduct social media screening. b) Out of 30 job listings, fewer than 17 will conduct social media screening. c) Out of 30 job listings, exactly between 19 and 22 (including 19 and 22) will conduct social media screening. show all steps for probabilities please. answer parts a-c.arrow_forward
- Question: we know that for rt. (x+ys s ا. 13. rs. and my so using this, show that it vye and EIXI, EIYO This : E (IX + Y) ≤2" (EIX (" + Ely!")arrow_forwardTheorem 2.4 (The Hölder inequality) Let p+q=1. If E|X|P < ∞ and E|Y| < ∞, then . |EXY ≤ E|XY|||X|| ||||qarrow_forwardTheorem 7.6 (Etemadi's inequality) Let X1, X2, X, be independent random variables. Then, for all x > 0, P(max |S|>3x) ≤3 max P(S| > x). Isk≤narrow_forward
- Theorem 7.2 Suppose that E X = 0 for all k, that Var X = 0} x) ≤ 2P(S>x 1≤k≤n S√2), -S√2). P(max Sk>x) ≤ 2P(|S|>x- 1arrow_forwardThree players (one divider and two choosers) are going to divide a cake fairly using the lone divider method. The divider cuts the cake into three slices (s1, s2, and s3).If the chooser's declarations are Chooser 1: {s3} and Chooser 2: {s3}, which of the following is a fair division of the cake?arrow_forwardTheorem 1.4 (Chebyshev's inequality) (i) Suppose that Var X x)≤- x > 0. 2 (ii) If X1, X2,..., X, are independent with mean 0 and finite variances, then Στη Var Xe P(|Sn| > x)≤ x > 0. (iii) If, in addition, X1, X2, Xn are identically distributed, then nVar Xi P(|Sn> x) ≤ x > 0. x²arrow_forwardTheorem 2.5 (The Lyapounov inequality) For 0arrow_forwardTheorem 1.6 (The Kolmogorov inequality) Let X1, X2, Xn be independent random variables with mean 0 and suppose that Var Xk 0, P(max Sk>x) ≤ Isk≤n Σ-Var X In particular, if X1, X2,..., X, are identically distributed, then P(max Sx) ≤ Isk≤n nVar X₁ x2arrow_forwardTheorem 3.1 (The Cauchy-Schwarz inequality) Suppose that X and Y have finite variances. Then |EXYarrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- Algebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal LittellElementary Geometry For College Students, 7eGeometryISBN:9781337614085Author:Alexander, Daniel C.; Koeberlein, Geralyn M.Publisher:Cengage,
Algebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal LittellElementary Geometry For College Students, 7eGeometryISBN:9781337614085Author:Alexander, Daniel C.; Koeberlein, Geralyn M.Publisher:Cengage,Lecture 46: Eigenvalues & Eigenvectors; Author: IIT Kharagpur July 2018;https://www.youtube.com/watch?v=h5urBuE4Xhg;License: Standard YouTube License, CC-BYWhat is an Eigenvector?; Author: LeiosOS;https://www.youtube.com/watch?v=ue3yoeZvt8E;License: Standard YouTube License, CC-BY