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
ELEN [110]
3 years ago
6

(In Java) An n X n matrix is called a positive Markov matrix if each element is positive and the sum of the elements in each col

umn is 1. Write the following method to check whether a matrix is a Markov matrix.
public static boolean isMarkovMatrix(double[][] m)
Write a test program that prompts the user to enter a 3 X 3 matrix of double values and tests whether it is a Markov matrix.
Sample run:
Enter a 3-by-3 matrix row by row:
0.15 0.875 0.375
0.55 0.005 0.225
0.30 0.12 0.4
It is a Markov matrix
Computers and Technology
1 answer:
Stells [14]3 years ago
5 0

Answer:

In Java:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 System.out.print("Enter a 3 x 3 matrix: ");

 double[][] myArr = new double[3][3];

 for(int i =0;i<3;i++){

        for(int j = 0;j<3;j++){

         myArr[i][j] = input.nextDouble();}}

 boolean isMarkov = true;

 double colsum = 0.00;

 for(int i =0;i<3;i++){

     for(int j = 0;j<3;j++){

         colsum += myArr[j][i];}

     if(colsum != 1.00){

         isMarkov = false;

         break;}

     colsum = 0.00;

 }

 if(isMarkov){    System.out.print("It is a Markov matrix"); }

 else{  System.out.print("It is a not Markov matrix"); }

}

}

Explanation:

This line prompts the user for a 3\ x\ 3 matrix

 System.out.print("Enter a 3\ x\ 3 matrix: ");

This declares a 3 x 3 matrix

 double[][] myArr = new double[3][3];

The following iteration gets input for the 3\ x\ 3 matrix

<em>  for(int i =0;i<3;i++){</em>

<em>         for(int j = 0;j<3;j++){</em>

<em>          myArr[i][j] = input.nextDouble();}}</em>

This declares and initializes a boolean variable to true

 boolean isMarkov = true;

This declares and initializes colsum to 0 i.e. the sum of each column

 double colsum = 0.00;

The following iteration sums up each column

<em>  for(int i =0;i<3;i++){</em>

<em>      for(int j = 0;j<3;j++){</em>

<em>          colsum += myArr[j][i];}</em>

This checks if the column sum is not 1

     if(colsum != 1.00){

If true that the column sum is not 1, the boolean variable is updated to false

         isMarkov = false;

And the loop is terminated

        break;}

     colsum = 0.00;

 }

If isMarkov is true, the system prints that it is a Markov matrix

 if(isMarkov){    System.out.print("It is a Markov matrix"); }

If isMarkov is false, the system prints that it is not a Markov matrix

 else{  System.out.print("It is a not Markov matrix"); }

You might be interested in
Task 2
adelina 88 [10]

The program is an illustration of file manipulations

<h3>What are file manipulations?</h3>

File manipulations are program statements that are used to write & append to file, and also read from the file

<h3>The actual program in Python</h3>

Assume the file name is top10.txt, the program in Python where comments are used to explain each line is as follows:

#This opens the file

a_file = open("top10.txt")

#This reads the file contents

file_contents = a_file.read()

#This prints the contents

print(file_contents)

Read more about file manipulations at:

brainly.com/question/15683939

3 0
2 years ago
What is the difference between (IF instructions &amp; WHILE instructions )<br> 0<br> 를 들<br> T<br> !
lara31 [8.8K]

Answer:

While statements determine whether a statement is true or false. If what’s stated is true, then the program runs the statement and returns to the first step. If what’s stated is false, the program exits the while and goes to the next statement. An added step to while statements is turning them into continuous loops. If you don’t change the value so that the condition is never false, the while statement becomes an infinite loop.

If statements are the simplest form of conditional statements, statements that allow us to check conditions and change behavior/output accordingly. The part of the statement following the if is called the condition. If the condition is true, the instruction in the statement runs. If the condition is not true, it does not. The if statements are also compound statements. They have a header (if x) followed by an indented statement (an instruction to be followed is x is true). There is no limit to the number of these indented statements, but there must be at least one.

7 0
3 years ago
You are working with a worksheet on which cell B3 is selected. You hold down the Ctrl key and the Shift key and click cell B6. W
Keith_Richards [23]

Answer:

"B3 and B6 will selected"

Explanation:

  • If the worksheet is opened by the user and he is in the cell B3, then the B3 and B6 are selected, If the user clicks the B6 after pressing the ctrl and the shift key.
  • The shift and ctrl are used to select any two cells in the MS-Excel worksheet.
  • The above question asked about which cell is selected when the user in on cell B3 and press the B6 while holding the ctrl and shift key. So the answer is "B3 and B6".
8 0
3 years ago
Some attackers might create a peer-to-peer network that connects a wireless device directly to another wireless device, such as
julia-pushkina [17]

Answer:

ad-hoc network

Explanation:

Ad-hoc network is a type of network that is setup to allow computers to talk to each other without the use of a router or server. The computers communicate directly with each other. In windows operating system ad-hoc is implemented as a communication mode which can be turned on.

4 0
3 years ago
2) A simple operating system supports only a single directory but allows it to have arbitrarily many files with arbitrarily long
puteri [66]

Answer:

Yes it can

Explanation:

The answer is Yes something approximating a hierarchical file system can be simulated. A way to carry out this simulation is through appending to each file name the name of the directory that contains it. But an offside to it is that it may end up becoming too complex to manage because the file name may be too long.

8 0
3 years ago
Other questions:
  • Tasha purchased a new tablet. She has several questions about how to connect to the internet, download apps, install software, a
    5·1 answer
  • To type the letter address, _________ space from the dateline
    9·2 answers
  • A(n) ____ is a collection of one or more program statements combined to perform some action
    14·1 answer
  • When the hyper-v role is added to a windows server 2012 r2 server, what is loaded first during boot?
    6·1 answer
  • What three things in the third generation of computing helped get programming enthusiasts more involved with computers? Select 3
    12·2 answers
  • Distributed computing is a term that describes the work that autonomous computers can do to achieve a common goal, especially in
    10·1 answer
  • What summarizes a data source into a grid of rows and columns?
    12·2 answers
  • How to run android apps on a chromebook?
    15·1 answer
  • Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    12·1 answer
  • What is number system in computer language ​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!