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
NeX [460]
4 years ago
8

In this this problem you will be using for loops to take a matrix of random number and create a new matrix that is the same as t

he random matrix, but with zeros on the diagonal. a) Create matrix m that is a 10x10 matrix of random whole numbers from 1 to 20. You will have to manipulate the random number generator function to modify the interval and get only whole numbers. b) Create a for loop that runs for index i equal to the index for every row in the matrix. Next, create a nested for loop that runs for index j equal to the index for every column in the matrix. This is very similar to the Your Turn - Extra slide of Lecture 13. c) Now, we want to use our for loops to create a new niatrix, n, that is equal to matrix m, but with zeros on the diagonal. You should use an if/else statement to create this new matrix. If the location is on the diagonal (i=j), then the value of matrix n at the location will be zero. Otherwise, the value of matrix n equals the value of matrix m at each location
Engineering
1 answer:
motikmotik4 years ago
5 0

Answer:

import numpy as np

# creating matrix of order 10*10 with random numbers between 1 and 20

m = np.random.randint(1,20, size=(10,10))

# create new matrix which reads matrix m and produces zero along the diagonal

n = np.random.randint(1,20, size=(10,10)) # create new matrix, n

for i in range(0,10): # loop through row of matrix

 for j in range(0,10): # loop through column of the matrix

   if i==j: # check for the diagonal element

     n[i][j] = 0 # asign diagonal value to zero

   else:

     n[i][j] = m[i][j] # assign the value of matrix m to n

# displaying m and n matrix in the given format using disp function

from io import StringIO

buf = StringIO()

np.disp(m,device=buf)

m = buf.getvalue()

m = m[1:-1] #removing the extra [ and ]from beginning and end

print("m = ")

print(m.replace(" [","").replace('[',"").replace(']',""))

buf = StringIO()

np.disp(n,device=buf)

n = buf.getvalue()

n = n[1:-1] #removing the extra [ and ]from beginning and end

print("n = ")

print(n.replace(" [","").replace('[',"").replace(']',""))

Explanation:

You might be interested in
Examine a process whereby air at 300 K, 100 kPa is compressed in a piston/cylinder arrangement to 600 kPa. Assume the process is
professor190 [17]

Answer:

See attachment and explanation.

Explanation:

- The following question can be solved better with the help of a MATLAB program as follows. The code is given in the attachment.

- The plot of the graph is given in attachment.

- The code covers the entire spectrum of the poly-tropic range ( 1.2 - 1.6 ) and 20 steps ( cases ) have been plotted and compared in the attached plot.

3 0
3 years ago
2.4: Add a method called setValue(), and the description of setValue is: public int setValue(long searchKey) In this method, the
Yanka [14]

Answer:

Below is java code that must be used for the given question:

// highArray.java

// demonstrates array class with high-level interface

// to run this program: C>java HighArrayApp

////////////////////////////////////////////////////////////////

class HighArray

  {

  private long[] a;                 // ref to array a

  private int nElems;               // number of data items

  //-----------------------------------------------------------

  public HighArray(int max)         // constructor

     {

     a = new long[max];                 // create the array

     nElems = 0;                        // no items yet

     }

  //-----------------------------------------------------------

  public setValue find(long searchKey)

     {                              // find specified value

     int j;

     for(j=0; j<nElems; j++)            // for each element,

        if(a[j] == searchKey)           // found item?

           break;                       // exit loop before end

     if(j == nElems)                    // gone to end?

        return false;                   // yes, can't find it

     else

        return true;                    // no, found it

     }  // end find()

  //-----------------------------------------------------------

  public void insert(long value)    // put element into array

     {

     a[nElems] = value;             // insert it

     nElems++;                      // increment size

     }

  //-----------------------------------------------------------

  public void display()             // displays array contents

     {

     for(int j=0; j<nElems; j++)       // for each element,

        System.out.print(a[j] + " ");  // display it

     System.out.println("");

     }

  //-----------------------------------------------------------

  }  // end class HighArray

////////////////////////////////////////////////////////////////

class HighArrayApp

  {

  public static void main(String[] args)

     {

     int maxSize = 100;            // array size

     HighArray arr;                // reference to array

     arr = new HighArray(maxSize); // create the array

     arr.insert(77);               // insert 10 items

     arr.insert(99);

     arr.insert(44);

     arr.insert(55);

     arr.insert(22);

     arr.insert(88);

     arr.insert(11);

     arr.insert(00);

     arr.insert(66);

     arr.insert(33);

     arr.display();                // display items

     int searchKey = 35;           // search for item

     if( arr.find(searchKey) )

        System.out.println("Found " + searchKey);

     else

        System.out.println("Can't find " + searchKey);

     }  // end main()

  }  // end class HighArrayApp

Explanation:

6 0
3 years ago
A triangular plate with a base 5 ft and altitude 3 ft is submerged vertically in water. If the base is in the surface of water,
Scorpion4ik [409]

Answer:

Hydrostatic force = 41168 N

Explanation:

Complete question

A triangular plate with a base 5 ft and altitude 3 ft is submerged vertically in water  so that the top is 4 ft below the surface. If the base is in the surface of water, find the force against onr side of the plate. Express the hydrostatic force against one side of the plate as an integral and evaluate it. (Recall that the weight density of water is 62.5 lb/ft3.)

Let "x" be the side length submerged in water.

Then

w(x)/base = (4+3-x)/altitude

w(x)/5 = (4+3-x)/3

w(x) = 5* (7-x)/3

Hydrostatic force = 62.5 integration of  x * 4 * (10-x)/3 with limits from 4 to 7

HF = integration of 40x - 4x^2/3

HF = 20x^2 - 4x^3/9 with limit 4 to 7

HF = (20*7^2 - 4*7^(3/9))- (20*4^2 - 4*4^(3/9))

HF = 658.69 N *62.5 = 41168 N

4 0
3 years ago
A horizontal curve of a two-lane undivided highway (12-foot lanes) has a radius of 678 feet to the center line of the roadway. A
OLEGan [10]

Answer:

maximum speed for safe vehicle operation = 55mph

Explanation:

Given data :

radius ( R ) = 678 ft

old building located ( m )= 30 ft

super elevation = 0.06

<u>Determine the maximum speed for safe vehicle operation </u>

firstly calculate the stopping sight distance

m = R ( 1 - cos \frac{28.655*S}{R} )  ----  ( 1 )

R = 678  

m ( horizontal sightline ) = 30 ft

back to equation 1

30 = 678 ( 1 - cos (28.655 *s / 678 ) )

( 1 - cos (28.655 *s / 678 ) )  = 30 / 678 = 0.044

cos \frac{28.65 *s }{678}  = 1.044

hence ; 28.65 * s = 678 * 0.2956

s = 6.99 ≈ 7 ft

next we will calculate the design speed ( u ) using the formula below

S = 1.47 ut  + \frac{u^2}{30(\frac{a}{3.2} )-G1}  ----  ( 2 )

t = reaction time,  a = vehicle acceleration, G1 = grade percentage

assuming ; t = 2.5 sec , a = 11.2 ft/sec^2, G1 = 0

back to equation 2

6.99 = 1.47 * u * 2.5 + \frac{u^2}{30[(11.2/32.2)-0 ]}

3.675 u  + 0.0958 u^2 - 6.99 = 0

u ( 3.675 + 0.0958 u ) = 6.99

5 0
3 years ago
A flow rate sensing device used on a liquid transport pipeline functions as follows. The device provides a 5-bit output where al
marysya [2.9K]

Answer:

Explanation:

The step by step analysis is as shown in the attached files.

8 0
3 years ago
Other questions:
  • Practice Problem: Large-Particle CompositesThe mechanical properties of a metal may be improved by incorporating fine particles
    5·1 answer
  • How should employees talk to clients)
    9·1 answer
  • An electric field is expressed in rectangular coordinates by E = 6x2ax + 6y ay +4az V/m.Find:a) VMN if point M and N are specifi
    9·1 answer
  • It is possible to have liquid water at 200°C. a)-True b)- False
    14·1 answer
  • Give the approximate temperature at which creep deformation becomes an important consideration for each of the following metals:
    5·1 answer
  • 0 - 1"<br> -20<br> -15<br> -10<br> 5<br> 0 1 2 3<br> 0
    14·1 answer
  • Three possible career opportunities in embedded systems engineering
    11·1 answer
  • Effective presentations are: Have a central message Colorful and exciting Have many messages Are influence by a setting Created
    15·2 answers
  • Two identical bulbs in parallel in a radio create a total resistance of 15 ohms in the circuit. What's the resistance of each of
    6·1 answer
  • assuming complementary inputs are available, the minimum number of transistors needed to realize a two input xor gate is:
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!