Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 1, Problem 18C

Explanation of Solution

Implementation of norm(v):

The norm() method takes the input parameter of “vec” to return the Euclidean norm of “vec” array of coordinates.

//Function definition

public static double norm(double[ ] vec)      

{

/*Call the norm() by passing the “vec” and “2” and return the result of computed value. */

return norm(vec,2);

}

Explanation:

In norm() method,

  • It takes the input parameter of “vec”.
  • Call the norm() method by passing the “vec” and “2” and return the result of computed value of p-norm value of “vec” array of coordinates.

Implementation of norm(v, p):

The norm() method takes the input parameter of “vec” and “pow” to return the p-norm value of “vec” array of coordinates.

//Function definition

public static double norm(double[ ] vec, int pow)

{

//Declare the variables

int sum = 0;

double exp = 1.0/pow;

//Loop executes until from “i” to "vec"

for (double i : vec)

//Add the "sum" and the power of number

sum += Math.pow(i,pow);

//Return the return

return Math.pow(sum, exp);

}

Explanation:

In norm() method,

  • It takes the input parameter of “vec” and “pow”.
  • Loop executes until the “vec” to add the sum and power of input.
  • Return the computed p-norm value of “vec” array of coordinates.

Complete Program:

/**********************************************************

* Program demonstrates how to determine the Euclidean norm*

* for two-dimensional vectors...

Blurred answer
Students have asked these similar questions
Given a vector x=[12 3 4 5 . ], take the square of each element and sum them up. What should be the dimension of the vector x so that the squared sum (as above) is as close as possible to 1000 but not more than 1000? ....
Please written by computer source
Pls Use Python If there is a non-singular matrix P such as        P-1AP=D  , matrix A is called a diagonalizable matrix. A, n x n square matrix is ​​diagonalizable if and only if matrix A has n linearly independent eigenvectors. In this case, the diagonal elements of the diagonal matrix D are the eigenvalues ​​of the matrix A.   A=({{1, -1, -1}, {1, 3, 1}, {-3, 1, -1}}) : 1 -1 -1 1 3 1 -3 1 -1     a)Write a program that calculates the eigenvalues ​​and eigenvectors of matrix A using NumPy.   b)Write the program that determines whether the D matrix is ​​diagonal by calculating the D matrix, using NumPy. Ps: Please also explain step by step with " # "

Chapter 1 Solutions

Data Structures and Algorithms in Java

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole