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
You often insert your company's logo into a document you create.one way to make it easier for you to quickly insert it is to sav
eduard
Save the logo as a TEMPLATE.

A template is a pre-developed page layout in soft copy or hard copy used to make pages with the same pattern, style, or design.

In the above scenario, you can prepare a template with you logo in it and save it for future use. In the event that you need to create a new document, you only have to bring up the saved template and edit it with the new information that you need to type.

This way, you will not be hassled to manually add your logo to every new document you create.
5 0
2 years ago
What aviation first is janice brown credited with
Alla [95]

Janice Brown is a former teacher who flew the first long-distance solar-powered flight. She flew a small experimental solar-powered aircraft six miles.

Let me know if you have any questions.

7 0
2 years ago
State three positive uses of the computer in the government sector​
WINSTONCH [101]

Well Here I got 4

1. Email Functions

2. Distributing Payments

3. Record Keeping

4. Direct Mail Promotions

<em>Have A great night!</em>

<em></em>

6 0
3 years ago
A foreign exchange student brought his desktop computer from his home in Europe to the United States. He brought a power adapter
lidiya [134]
The European plug takes up 220 volts while the American one takes 110 volts.
6 0
2 years ago
True false are computer has four main parts​
Oliga [24]

Answer:

yes they are: Central Processor Unit (CPU)

Memory (RAM)

Input (keyboard, mouse, etc)

Output (monitor, printer, etc)

Explanation:

True

4 0
3 years ago
Read 2 more answers
Other questions:
  • The trademarked name of the accepted standard for configuring wireless networks is _______________
    12·1 answer
  • HELP ASAP U GET BRAINLIEST
    15·2 answers
  • What is Mars internal composition
    7·1 answer
  • Consider relations A and B. Relation A represents the entity on the ""one side"" of a one-to-many relationship; Relation B repre
    11·1 answer
  • Given the following MIPS Code Fragment:
    14·1 answer
  • (15 POINTS) When an error is made in HTML code, the browser does what?
    11·1 answer
  • 1. Write a recursive method to determine if a character is in a list of characters in O(logN) time. Mathematically prove (as we
    13·1 answer
  • A Cisco Catalyst switch has been added to support the use of multiple VLANs as part of an enterprise network. The network techni
    5·1 answer
  • Superclass in python explanation
    7·1 answer
  • What is one reason why a business may want to move entirely online?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!