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
Perform the following vector multiplication of two vectors and find the y-component of the resulting vector, c. č = à xb ā = [ax ay az] b = [b, by b;] where ax = 5, ay = 5, az = 5 and by = 9, by = -7, b, = -8. %3D Your Answer:
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]
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