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
Let l be a line in the x-yplane. If l is a vertical line, its equation is x = a for some real number a. Suppose l is not a vertical line and its slope is m. Then the equation of l is y = mx + b, where b is the y-intercept. If l passes through the point (x₀, y₀), the equation of l can be written as y - y₀ = m(x - x₀). If (x₁, y₁) and (x₂, y₂) are two points in the x-y plane and x₁ ≠ x₂, the slope of line passing through these points is m = (y₂ - y₁)/(x₂ - x₁). Instructions Write a program that prompts the user for two points in the x-y plane. Input should be entered in the following order: Input x₁ Input y₁ Input x₂
Although the plot function is designed primarily for plotting standard xy graphs, it can be adapted for other kinds of plotting as well. b. Make a plot of the curve, which is defined parametrically by the equations               x = 2cosθ + cos2θ, y = 2sinθ - sin2θ,   where 0 < θ < 2π. Take a set of values of θ between zero and 2π and calculate x and y for each from the equations above, then plot y as a function of x.  b. Taking this approach a step further, one can make a polar plot r = f(θ) for some function f by calculating r for a range of values of θ and then converting r and θ to Cartesian coordinates using the standard equations x = r cosθ, y = r sinθ. Use this method to make a plot of the function r = ecosθ – 2 cos(4θ) + sin5 (θ/12) in the range 0 <= θ <= 24π.   use python code to answer the highlight one
The algorithm for computing the Hamming distance between two sequences of the same length implemented in R, for instance, by first splitting the sequences into vectors with the strsplit function and then using the sum function to count the number of positions at which the two vectors differ.

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