Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Function Name: aircontour Inputs 1. 2. (double) A 1xN vector representing the pr

ID: 3879291 • Letter: F

Question

Function Name: aircontour Inputs 1. 2. (double) A 1xN vector representing the pressures of warm air (double) Another 1xN vector representing the pressures of cold air Outputs 1. (logical) Whether or not there will be a change in weather Background Weather changes can occur as a result of collisions between warm and cold air masses As a meteorologist, you have measured the varying pressures of two air masses, one warm and one cold. As the two collide, you want to determine if there will be a change in weather. Function Description: Before you can compare the two vectors, you must first find the contour of each. The contour of a vector describes whether each transition between adjacent elements is increasing or decreasing. If the two vectors have the same contour, meaning both their pressures increase and decrease at the same points, then there will not be a change in weather, as the warm and cold pressure changes will cancel each other out. For the contours to be the same, the vectors DO NOT have to have the same values, nor does the amount by which elements increase or decrease have to be the same. Only the pattern of increasing and decreasing matters. The function should output false if and only if the two vectors have the same contour Example Consider the following vectors: v1- [2, 4, 31; v2 = [-2, 18, 8] These two vectors have the same contour because they both follow the pattern [increasing, decreasingl. Thus, there will not be a change in weather, and the output would be false Now consider these two vectors: [5, v3 = 3, 1); These vectors do not have the same contour. The first one follows the pattern [decreasing decreasing] while the second one is [increasing, decreasingl. Here the output would be true, v4- [1, 4, 1] Notes: Both vectors will always be the same length. Adjacent elements will never have the same value, l.e. there will never be a change of 0 A single number has the same contour as any other single number Make sure that your output is class logical and not double. You will get the problem wrong if you output a double 0 instead of a logical false. Hints: . The diff(). abs(), and isequal() functions will be useful. If N is a number, the sign of N can be found using the formula: sign N

Explanation / Answer

Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you


Save the following code in a file named airContour.m
===========================

function out = airContour(v1, v2)
  
%find the difference between adjacent elements for both the vectors
dv1 = diff(v1);
dv2 = diff(v2);
  
  
%get the sign of each element
signV1 = dv1 ./ abs(dv1);
signV2 = dv2 ./ abs(dv2);
  
%only if signs for corresponding elements in both vectors is same, the weather will not change
if isequal(signV1, signV2)
out = false;
else
out = true;
  
end
end

==================

Now either in command window or another file copy paste the following lines to test the function written above.
The value 0 in output is logical false and 1 is logical true.


v1 = [2, 4, 3];
v2 = [-2, 10, 8];

v3 = [5, 3, 1];
v4 = [1, 4, 1];

out1 = airContour(v1, v2)
out2 = airContour(v3, v4)