1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Taya2010 [7]
2 years ago
11

(a) Store last 7 digits of your student ID in a vector (7 element row or column vector). Write a MATLAB code which creates a 7x7

diagonal matrix, called ????, using last 7 digits of your student ID. Use for loop to accomplish the problem. Repeat the same problem with diag function in MATLAB. Name the matrix as ????. Comment if both ???? and ???? are the same. (b) Use if-else statement to decide and print if A(6,6) is odd or even. Now use if-elseif-else statement to check and print if A(3,3) is positive, negative, or zero. (c) Write a MATLAB code which generates a geometric sequence 35, 30, 25, … …, 5, 0 using for loop. (d) Write a MATLAB code which asks a user for an integer number and computes the factorial of that number. Use while loop to create the code. (e) Use vectors x = [3 7 2 1] and y = [4 3 9 1] and compute the following using for loop (i) ???? = ∑ x????y???? (ii) ???????? = x???? y???? ⁄ (iii) ???? = Reciprocal of the smaller of x???? ???????????? y???? . (f) Create a vector (name the vector as "A") with random 10 values from the interval [5, 25] and use for loop to find the greatest element of the vector (name the element as maxA). Then, use while loop to find the smallest element of the vector (name the element as minA. For the results (output) show the vectors A, maxA, and minA.
Computers and Technology
1 answer:
astra-53 [7]2 years ago
5 0

Answer:

MATLAB code explained below with appropriate comments for better understanding

Explanation:

clc

clear all

ID = [1 2 3 4 5 6 7]; % Replace this with your student ID

%(a)

A = zeros(7);

for i=1:7

 

A(i,i)= ID(i);

 

end

fprintf('A =\n');

disp(A);

B = diag(ID);

fprintf('B =\n');

disp(B);

fprintf('Both A and B are same\n');

%(b)

if(mod(A(6,6),2)==0)

fprintf('A(6,6) is even\n');

else

fprintf('A(6,6) is odd\n');

end

%(c)

if(A(3,3)>0)

fprintf('A(3,3) is positive\n');

else if(A(3,3)<0)

fprintf('A(3,3) is negative\n');

else

fprintf('A(3,3)=0\n');

end

end

%(d)

fprintf('\nRequired series : ');

n = 35;

while n>=0

fprintf('%i',n);

if(n>0)

fprintf(', ');

end

n = n - 5;

end

fprintf('\n');

%(e)

n = input('\nInput an integer : ');

fprintf('%i! = ',n);

F = 1;

while n>1

F = F * n;

n = n - 1;

end

fprintf('%i\n',F);

%(f)

clear all

x = [3 7 2 1];

y = [4 3 9 1];

A = 0;

C = x(1);

for i=1:length(x)

A = A + x(i)*y(i);

B(i) = x(i)/y(i);

if(min(x(i),y(i))<C)

C = min(x(i),y(i));

end

end

C = 1/C;

fprintf('\nA = %i\n',A);

fprintf('B = ');

disp(B)

fprintf('C = %0.5g\n',C);

%(g)

clear all

A = randi([5 25],[1,10]);

maxA = A(1);

for i = 2:10

if(maxA<A(i))

maxA = A(i);

end

end

minA = A(1);

i = 2;

while i<11

if(minA>A(i))

minA = A(i);

end

i = i+1;

end

fprintf('\nA = ');

disp(A);

fprintf('maxA = %i\n',maxA);

fprintf('minA = %i\n',minA);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%output

A =

1 0 0 0 0 0 0

0 2 0 0 0 0 0

0 0 3 0 0 0 0

0 0 0 4 0 0 0

0 0 0 0 5 0 0

0 0 0 0 0 6 0

0 0 0 0 0 0 7

B =

1 0 0 0 0 0 0

0 2 0 0 0 0 0

0 0 3 0 0 0 0

0 0 0 4 0 0 0

0 0 0 0 5 0 0

0 0 0 0 0 6 0

0 0 0 0 0 0 7

Both A and B are same

A(6,6) is even

A(3,3) is positive

Required series : 35, 30, 25, 20, 15, 10, 5, 0

Input an integer : 6

6! = 720

A = 52

B = 0.7500 2.3333 0.2222 1.0000

C = 1

A = 25 14 7 10 13 17 10 17 19 9

maxA = 25

minA = 7

>>

You might be interested in
How to make a 'Sign in with replit' button in replit (Node.js) will make brainliest
Y_Kistochka [10]

hit the sign in botten or create new account

3 0
3 years ago
Read 2 more answers
Whats included in ms office 2013 professional?
MrMuchimi
Powerpoint, word document, and excel
3 0
3 years ago
C was created to work with UNIX systems in1972, and would be the foundation for several other programming languages, including j
san4es73 [151]

Answer:

True

Explanation:

C language is developed with the help of UNIX in 1972. It was developed by Denis Ritchie at Bell labs. many languages are developed with the help of C Platform. Such as C++, C sharp and Java.

7 0
3 years ago
Using the Internet, search and discuss why naming conventions are important and why programmers should consistently follow them.
LiRa [457]

Answer:

Answered below

Explanation:

Some variable naming conventions include;

1) Variable should begin with either a letter or an underscore.

2) Variables having multiple words should have the first letter of every word after the first word, capitalized. This is the camelCase style.

3) variables should not be named after any of the inbuilt keywords except on special operations to override the original function of such keyword.

4) variable names are case-sensitive.

The importance of following these conventions is to maintain readability and consistency of code. Failure to follow these conventions may lead to chaotic codes, bugs and inefficient performance.

7 0
3 years ago
How would you add the double 75.6 to the end of an ArrayList of Doubles named myDoubles?
eduard

Answer:

myDoubles.add(75.6);

Explanation:

ArrayList<Double> myDoubles = new ArrayList<Double>();

myDoubles.add(10.8);

myDoubles.add(92.46);

myDoubles.add(75.6);

The above code creates a double ArrayList called myDoubles. We add 10.8 and 92.46 initially. After these numbers, 75.6 is added to the myDoubles using <em>add</em> method (You need to type the list name, ".", and the method name to add the number)

6 0
2 years ago
Other questions:
  • Text messaging is an example of nonverbal communication. Please select the best answer from the choices provided. T F
    7·2 answers
  • If a user wants to add an expansion card to increase the memory of a computer, where should the user insert the card?
    12·2 answers
  • 2
    11·1 answer
  • William found out that someone used his report on american culture without his permission. what is william a victim of?
    11·1 answer
  • Which of the following is a benefit, as well as a risk, associated with peer-to-peer networks?
    6·2 answers
  • When compared to traditional desktop customers, why are mobile phone users much more likely to book a room or airline reservatio
    12·1 answer
  • Son opciones de configuración espacio multimedia llamado blog
    9·1 answer
  • Write a method named isNumericPalindrome that accepts an integer parameter named num. If num is a palindrome the method must ret
    6·1 answer
  • Write a public static method named evens that takes in 1 argument int a, and returns a String containing all positive even numbe
    8·1 answer
  • How many free passes do you get for skipping videos and getting answers
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!