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

Please create a program code for the problems so I can learn how to slove them.

ID: 3810353 • Letter: P

Question

Please create a program code for the problems so I can learn how to slove them.

Write a Matlab program using FOR loop that computes the sum of the elements of an array. Load the lab8.mat file and from it, use Array1 as the sample array to compute the sum. Use the length command to know the elements in the array. 2. Write a Matlab program using FOR loop that computes the sum of the even-indexed numbers of an array. Use Array1 from the lab8.mat file. Use the length command to know the elements in the array. 3. Write a Matlab program using FOR loop that computes the largest element of an array. Load lab8.mat, and use Array1 as the sample array to test your program. Use the length command to know the elements in the array. 4. Write a nested FOR loop sing two for loops & two fprintf statements to generate the following pattern 5. Using a FOR loop write a program that given a vector of numbers computes how many numbers are greater than 10. Use Array2 to check your program. 6. Write a Matlab program using FOR loop that prints a given row or column vector in reverse. Load lab8.mat and use Array2 as a sample for testing row vector and use Array3 as a sample to test the functionality of reversing a column vector. Use the length command to know the elements in the array. Display matrix using following command disp and mat2str

Explanation / Answer

Here is the code for the first 4 problems:

% 1. Write a Matlab program using FOR loop that computes the sum of the

% elements of an array. Load Array1.

Array1 = [11 22 33 44 55 66 77 88 99];

sum = 0;

for i = 1 : length(Array1)

sum = sum + Array1(i);

end

fprintf('The sum of the elements of the array is: %d ', sum);

% 2. Write a Matlab program using FOR loop that computes the sum of the

% even-indexed numbers of an array. Load Array1.

% Use the length command to know the elements in the array.

% Array1 =

% 71 3 28 5 10 82 69 32 95 3 44 38 77 80 19

Array1 = [71 3 28 5 10 82 69 32 95 3 44 38 77 80 19];

sum = 0;

for i = 2 : 2 : length(Array1)

sum = sum + Array1(i);

end

fprintf('The sum of even-indexed elements of Array2 is: %d ', sum);

% 3. Write a Matlab program using FOR loop that computes the largest

% element of an array. Load Array1.

maxValue = Array1(1);

for i = 1 : length(Array1)

if Array1(i) > maxValue

maxValue = Array1(i);

end

end

fprintf('The maximum value in the Array1 is: %d ', maxValue);

%4. Write a nested FOR loop to print a pattern reverse right angled

%triangle.

for i = 1 : 5

for j = 1 : 5 - i + 1

fprintf('*');

end

fprintf(' ');

end

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