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? ....
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…
A vector has the coordinates of VB = = [10, 20, 30] in frame {B}. Given the following homogeneous transformation between frames {A} and {B}, find the coordinates of this vector in frame {A}, i.e., find VA. 0.866 - 0.500 0.000 11.0 HÂ 0.500 0.866 0.000 -3.0 = 0.000 0.000 1.000 9.0 -0 0 0

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