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

2. Write a MATLAB script that does the following: a. Creates a row vector ofleng

ID: 2268623 • Letter: 2

Question

2. Write a MATLAB script that does the following: a. Creates a row vector oflength 200. Th first elem e elements should be powers of /3. The ent will be (/3), the second element will be (/3), and the last element will be (/3)200 b. P rints all elements of the row vector from part a to the command window, using ormatted printing. There should be five places to the left of the decimal point and ive places to the right of the decimal point. There should be a new line after each number. The printed column of numbers should be right justified. This will be true if all decimal points lie along one (unshown) vertical line. Your script should make MATLAB do the heavy lifting. This means there should be an economy of style. In order to enter your script into a text editor, it should not be necessary to type hundreds of numbers. For full credit, your script must work. This means that if I typed your script exactly as you wrote it into a MATLAB script-m file and then executed that file, it would produce the desired results. (40pts)

Explanation / Answer

clc
clear all
L=200; %Length of row vector
for i=1:L
x(i)=(pi/3)^i; %Generates a row vector of size L
end
format='%5.5f'; %Formating style by default it gives right justify
fprintf('The vector is: ') %to print
for j=1:L
fprintf([format ' '], x(j)) %to print row values one by one with right justify alignment.
end

Output:

The vector is:
1.04720
1.09662
1.14838
1.20258
1.25934
1.31878
1.38102
1.44620
1.51446
1.58594
1.66079
1.73918
1.82126
1.90722
1.99724
2.09150
2.19021
2.29359
2.40184
2.51520
2.63391
2.75822
2.88841
3.02473
3.16749
3.31699
3.47354
3.63749
3.80917
3.98895
4.17722
4.37437
4.58083
4.79704
5.02344
5.26054
5.50882
5.76883
6.04110
6.32623
6.62481
6.93748
7.26492
7.60780
7.96687
8.34289
8.73665
9.14900
9.58081
10.03300
10.50654
11.00242
11.52171
12.06550
12.63496
13.23130
13.85579
14.50975
15.19457
15.91172
16.66271
17.44915
18.27271
19.13514
20.03827
20.98402
21.97442
23.01156
24.09765
25.23500
26.42603
27.67327
28.97938
30.34714
31.77945
33.27936
34.85006
36.49490
38.21737
40.02114
41.91004
43.88809
45.95950
48.12868
50.40023
52.77900
55.27004
57.87865
60.61038
63.47104
66.46672
69.60378
72.88891
76.32909
79.93164
83.70421
87.65485
91.79194
96.12430
100.66113
105.41209
110.38728
115.59729
121.05320
126.76661
132.74969
139.01515
145.57632
152.44717
159.64230
167.17703
175.06737
183.33012
191.98286
201.04398
210.53276
220.46939
230.87501
241.77174
253.18278
265.13238
277.64598
290.75019
304.47289
318.84326
333.89189
349.65076
366.15342
383.43497
401.53216
420.48350
440.32929
461.11175
482.87510
505.66562
529.53180
554.52440
580.69660
608.10405
636.80508
666.86072
698.33491
731.29461
765.80992
801.95427
839.80455
879.44127
920.94874
964.41527
1009.93331
1057.59969
1107.51580
1159.78784
1214.52698
1271.84968
1331.87787
1394.73925
1460.56752
1529.50274
1601.69152
1677.28744
1756.45130
1839.35150
1926.16438
2017.07462
2112.27561
2211.96984
2316.36940
2425.69637
2540.18330
2660.07373
2785.62269
2917.09726
3054.77711
3198.95511
3349.93796
3508.04682
3673.61804
3847.00382
4028.57298
4218.71176
4417.82462
4626.33513
4844.68681
5073.34417
5312.79359
5563.54444
5826.13011
6101.10919
6389.06660
6690.61490
7006.39554
7337.08025
7683.37247
8046.00883
8425.76075
8823.43602
9239.88059
9675.98033
10132.66291

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote