(MATLAB PROGRAMMING) use the data values shown below to create a function to dis
ID: 3827980 • Letter: #
Question
(MATLAB PROGRAMMING)
use the data values shown below to create a function to display the max and min y value and the corresponding x value the min and max occur at in two ways:
1. sort the y column
2. use the min/max function
Here is the data:
No. x y No. x y
1 4.91 8.18 11 0.94 0.21
2 3.84 7.49 12 0.59 1.73
3 2.41 7.11 13 0.69 3.96
4 2.62 6.15 14 3.04 4.26
5 3.78 6.62 15 1.01 6.75
6 0.52 3.30 16 3.60 6.67
7 1.83 2.05 17 4.53 7.70
8 2.01 2.83 18 6.13 7.31
9 0.28 1.16 19 4.43 9.05
10 1.08 0.52 20 4.12 10.95
Display which method is faster.
Your answers should all be through code. For example do not run each code and watch the time, then state which is faster. Instead the code should calculate the times, compare the times, then display the result.
Explanation / Answer
CODE:
The below code has been executed in Matlab prompt.
>> A = [4.91 8.18; 3.84 7.49; 2.41 7.11; 2.62 6.15; 3.78 6.62; 0.52 3.30; 1.83 2.05; 2.01 2.83;0.28 1.16;1.08 0.52;0.94 0.21;0.59 1.73;0.69 3.96;3.04 4.26; 1.01 6.75;3.60 6.67; 4.53 7.70;6.13 7.31;4.43 9.05;4.12 10.95]
A =
4.9100 8.1800
3.8400 7.4900
2.4100 7.1100
2.6200 6.1500
3.7800 6.6200
0.5200 3.3000
1.8300 2.0500
2.0100 2.8300
0.2800 1.1600
1.0800 0.5200
0.9400 0.2100
0.5900 1.7300
0.6900 3.9600
3.0400 4.2600
1.0100 6.7500
3.6000 6.6700
4.5300 7.7000
6.1300 7.3100
4.4300 9.0500
4.1200 10.9500
Sort the second column.
>> sortrows(A,2)
ans =
0.9400 0.2100
1.0800 0.5200
0.2800 1.1600
0.5900 1.7300
1.8300 2.0500
2.0100 2.8300
0.5200 3.3000
0.6900 3.9600
3.0400 4.2600
2.6200 6.1500
3.7800 6.6200
3.6000 6.6700
1.0100 6.7500
2.4100 7.1100
6.1300 7.3100
3.8400 7.4900
4.5300 7.7000
4.9100 8.1800
4.4300 9.0500
4.1200 10.9500
--------------------------------------
>> max(A)
ans =
6.1300 10.9500
>> min(A)
ans =
0.2800 0.2100
-----------------------------------
Obviously, second method is faster.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.