bdavpid-2448716-d a. Evaluate the following sum using a for loop: 10 72 72=1 Dis
ID: 2268753 • Letter: B
Question
bdavpid-2448716-d a. Evaluate the following sum using a for loop: 10 72 72=1 Display the value of x using disp command after the end of the for loop Evaluate the following sum using a while loop: b. c. m = 1 d. e. Display the value of y using disp command after the end of the while loop Submit your code as.m file via blackboard. 2- Create a new script that is called HW11b.m and save it. The script will do the following: Declare two variables row =5, col-6. Declare a (5x6) matrix called z with random entries using rand command a. b. i. You need to find the maximum value of the matrix using two nested for loops c. d. Initialize the maximum value MAX z(1,1). This initialization step is required. Use two nested for loops to go over each element in z i. Test the value of each element using if statement such that if the new element in z is > MAX then MAX become the new element f lztrc) MAXx) MAX=2(r,c); end e. Outside the loops, test your algorithm using a built-in function called max such that MAXI= max(max(z)) Such that MAX1 and MAX should have the same value.
Explanation / Answer
CODE;
1 a)for 1/n:-
clc;
clear all;
close all;
x=0;
%%USING FOR LOOP.
for n=1:1:10
x= x+1/n;
end
b)
fprintf('SUM FOR 1/n=')
disp(x);
c)
for 1/m^2:-
m=1;
y=0;
while m<=5
y=y+(1/(m^2));
m=m+1;
end
d)
fprintf('SUM FOR 1/m^2=')
disp(y);
output for d)
SUM FOR 1/m62=1.4636
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.