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
List the main industries in Sierra Leone​
Dafna11 [192]

Answer:

The main industries in Sierra Leone are: Diamond mining

Petroleum refining

Small - scale manufacturing (beverage, textiles,footwear)

Explanation:

They also engage in commercial ship repair

3 0
3 years ago
Will, there be any presents this year
garri49 [273]

Answer:

no why

Explanation:

8 0
3 years ago
Have y’all enjoyed The new hero floryn from Mobile legends
Angelina_Jolie [31]

Answer:

yo! but I'm a ex-mobile legends

5 0
3 years ago
Where was this taken
Korolek [52]

Answer:

Mostar city

Explanation:

look at the architecture

6 0
3 years ago
Read 2 more answers
. Use one command to create a /sales directory with the permissions of 770
mars1129 [50]

Answer:

mkdir -m 770 sales

Explanation:

The command mkdir is used to create a directory and the attribute or flag

-m is used to  assign permissions on create a folder.

Example:

mkdir -m 770 sales

Create a folder with permissions 770 with name sales

7 0
3 years ago
Other questions:
  • What is the Difference between raw_input and input?
    6·1 answer
  • Allow chrome to access the network in your firewall or antivirus settings. if it is already listed as a program allowed to acces
    15·1 answer
  • Why might location be important when searching for a job?
    10·2 answers
  • 1) List at least five smaller behaviors you could break the complex behavior "brushing my teeth" into.
    14·2 answers
  • a webmaster can be hired as a contract labor for a company meaning they are not an employee of the company true or false
    5·2 answers
  • 1. The Law of Superposition – the age of an object may be determined by the depth at which it is found, the deeper the object is
    14·1 answer
  • A External hackers have some access to a company's website and made some changes. Customers have submitted multiple complaints v
    11·1 answer
  • What is the function of the NOS? Select all that apply.
    5·2 answers
  • I umm… really need helpp<br> Can someone help me out <br> I’ll even mark u as brainiest !
    12·1 answer
  • Q1. Information systems that monitor the elementary activities and transactions of the organizations are: I a. Management-level
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!