Create a Matlab array whose values are 0.00714, 1.9989, -2019.07, 432.0, and -0.
ID: 3801342 • Letter: C
Question
Create a Matlab array whose values are 0.00714, 1.9989, -2019.07, 432.0, and -0.00000439 Using the F format descriptor, do the following: a. Print (using fprintf) each of the elements on its own line with four digits to the right of the decimal place. Experiment with the overall width until it is just large enough to do this and print with the same total field length for each number. b. Determine the minimum width needed to print all of the significant digits of the last element of the array. Use that to write a fprintf statement with the correct format to print the whole array on one line. Each element should print with the same width. If any of the numbers are touching, increase the field width until none do c. Repeat 2a, but start each line with the (integer) element number of the number being printed followed by a colon (:) and then a space and then the real element. For example, the first line should look like: 1: 0.0071 d. Repeat 2b, but print a single line before the real numbers with the (integer) element numbers of the numbers that will be below them on the next line. Use the same field width for the integers as for the reals in your format statements, so that they line up. Repeat problem 2 using the E format descriptor and 4 digits to the right of the decimal place for each case. For part b, note that Matlab's exponential format tries to use a mantissa m whose magnitude is such that 1 lessthanorequalto |m|Explanation / Answer
Matlab code
clc;
array = [0.00714, 1.9989, -2019.07, 432.0, -0.00000439]; % Creatinga matlab array
%%%%%%%% Problem 2%%%%%%%%%%%
% Part a)
fprintf('%0.4f ',array);
% Part b)
fprintf('%0.8f ',array);
% Part c)
fprintf('%d: %0.4f ',[(1:length(array));array]);
% Part d)
fprintf(1,' ');
fprintf('%0.1d: %0.4f ',[(1:length(array));array]);
%%%%%%%%%%% Problem 3%%%%%%%%%
% Part a)
fprintf('%0.4E ',array);
% Part b)
fprintf('%0.8E ',array);
% Part c)
fprintf('%d: %0.4E ',[(1:length(array));array]);
% Part d)
fprintf(1,' ');
fprintf('%0.1d: %0.4E ',[(1:length(array));array]);
OUTPUT
0.0071
1.9989
-2019.0700
432.0000
-0.0000
0.00714000
1.99890000
-2019.07000000
432.00000000
-0.00000439
1: 0.0071
2: 1.9989
3: -2019.0700
4: 432.0000
5: -0.0000
1: 0.0071
2: 1.9989
3: -2019.0700
4: 432.0000
5: -0.0000
7.1400E-03
1.9989E+00
-2.0191E+03
4.3200E+02
-4.3900E-06
7.14000000E-03
1.99890000E+00
-2.01907000E+03
4.32000000E+02
-4.39000000E-06
1: 7.1400E-03
2: 1.9989E+00
3: -2.0191E+03
4: 4.3200E+02
5: -4.3900E-06
1: 7.1400E-03
2: 1.9989E+00
3: -2.0191E+03
4: 4.3200E+02
5: -4.3900E-06
>>