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
Python broadcasting. Rewrite the following code without for-loops using vectorization and python broadcasting. (a) Given a data matrix X and vector beta compute a vector yhat: n = X. shape [0] yhat = np.zeros(n) for i in range(n): yhat [i] = beta [0]*X[i, 0] + beta[1]*X[i,1] + beta[2]*X[i, 1]*X[i,2] yhat beta[0]*X[: ,0] + beta[1]*X[:,1] + beta[2]*X[:,1]*X[:,2]
Suppose a computer program needs to apply an affine transformation to a complex three-dimensional object made up of 3000 points. The transformation is composed of 8 matrices (call them M1 through M3), so for each point (x, y, z) in the object, the following operation is performed. |-|-|-|-|| y M1 M2 M3 M7 M8 Each multiplication of a matrix times a column vector involves 16 multiplications (of one number by another) and 12 additions, for a total of 28 arithmetic operations. Each multiplication of a matrix times another matrix involves 64 multiplications and 48 additions, for a total of 112 arithmetic operations. (These numbers are not made up or chosen randomly; they are facts about 4 x 4 matrix multiplication.) The most inefficient way of applying the transformation to the 3000 points would be to begin on the left, multiplying M1 by M2, then that result by M3, and so on along the list from left to right, and doing the same 8 multiplications again for each of the 3000 points. How many…
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? ....

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