Question

In: Computer Science

So, I'm trying to get an average revolutions/minute from an input vector. Here's a sample vector:...

So, I'm trying to get an average revolutions/minute from an input vector.

Here's a sample vector:

V=[10200 11000 11800 12300 13100 13900 14400 15020 15850 16250]

The units are in ms so 10200 is 10.2 seconds.

The revolutions is between every successive value. So 11000 - 10200 is 1 revolutions per 800 ms and et cetera.

I need help figuring out a code that will allow me find the average cadence from the whole dataset.

Thank you in advance

Solutions

Expert Solution

Program :-

import java.util.Scanner;

public class VectorQ {

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.print("Enter number of sample vector data : ");
       int data = scan.nextInt();
      
       int i;
       float timeSum = 0f;
       int revolution =0;
       float result;
      
       System.out.println("Enter sample vector data : ");
       int[] v = new int[data];
       for(i=0; i<data; i++)
       {
           v[i] = scan.nextInt();
       }
      
       for(i=1; i<data; i++)
       {
           timeSum += (v[i] - v[i-1]);
           revolution++;
       }
      
       timeSum = (timeSum/1000f);
      
       result = (revolution/timeSum) * 60;
      
      
       System.out.println("average rate = " + (int)result + " revolution/minute");

       scan.close();
   }

}


Related Solutions

So, I'm trying to get revolutions/second from a given binary data. for example, the input binary...
So, I'm trying to get revolutions/second from a given binary data. for example, the input binary data is: V=[0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 1 0 ] let's say the distance between each value is arbitrary (for this example, you can use 0.1). Each 1 represents a full rotation of a bike pedal, and I'm trying to calculate the pedal rate from a given binary dataset in Matlab. How...
Javascript array of objects: I'm trying to get the input into an array of objects, and...
Javascript array of objects: I'm trying to get the input into an array of objects, and then display the information in a table using a for loop, but I don't think my path is right <!DOCTYPE html> <head> <title>Form</title> <meta charset="utf-8" /> <style media="screen"> h1 { text-align: center; } div { background-color: #pink; border: 2px solid green; padding: 15px; margin: 65px; } </style> <script> var list = []; total = 0; text = ""; function Product(item, quantity, costs){ this.item =...
I'm trying to get my code to loop back to let the user input multiple patients....
I'm trying to get my code to loop back to let the user input multiple patients. import java.util.Scanner; public class XYZ {    public static void main(String[] args) {           String response;        do{            //import scanner for input            Scanner input = new Scanner(System.in);               //prompt user input for last name            System.out.print("Enter last name ");            //output for last name            String...
I'm having trouble trying to create the italian, polish, and netherlands flag in C Here's my...
I'm having trouble trying to create the italian, polish, and netherlands flag in C Here's my code so far: #include<stdio.h> int main(){    int country_choice;    fprintf(stderr, "Enter the country_code of the chosen flag.(1 for Poland, 2 for Netherlands, 3 for Italy)");    fscanf(stdin, "%d", &country_choice);    switch (country_choice) { case 1: printf("Poland Flag\n"); printf("%c%c%c", 255,255,255); printf("%c%c%c", 220,20,60);    break;       case 2: printf("Italian Flag\n"); printf("%c%c%c", 0,146,70); printf("%c%c%c", 225,255,255); printf("%c%c%c", 206,43,55); break;    case 3: printf("Netherlands Flag\n"); printf("%c%c%c", 174,28,40);...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
I'm trying to get an understanding of this code as it was done in class, can...
I'm trying to get an understanding of this code as it was done in class, can someone please explain step by step what is happening? namespace BMI { class Program { static void Main(string[] args) { double height, weight; Console.Write("Enter person's height in inches: "); bool value1 = double.TryParse(Console.ReadLine(), out height); Console.Write("Enter weight in pounds: "); bool value2 = double.TryParse(Console.ReadLine(), out weight); if (!value1 || !value2) { Console.WriteLine("Not valid input."); } else { if (height < 5 || height >...
I'm trying to get the union of two arrays and I tried making a loop that...
I'm trying to get the union of two arrays and I tried making a loop that does so. I tried also making the loop give me the size of the array as well from the union of the two arrays. Please check my loop to see what is wrong with it because it is not doing what I want it to do. I'm also not sure how to get the correct size of the array after the two arrays have...
I'm trying to get my occupancy rate to output as 2 decimal places with a %...
I'm trying to get my occupancy rate to output as 2 decimal places with a % sign. I know this is a string but I need it to print as 2 decimal places like 59.23% or 25.36% I have system.out.printf("Occupancy rate: %2s", occupancy + "%"); but I'm still not getting 2 decimal places or the % sign. How can I fix this? I'm in beginning java so I can't use anything advanced. public class ResortAccomidations { public static void main(String[]...
I'm trying to make this C++ loan calculator but I can't get the program to output...
I'm trying to make this C++ loan calculator but I can't get the program to output what I need. For instance I know the formula is right and when I enter 100000 1.5 20 as my cin variables I should get 482.55 but I get 1543.31. What am I not seeing as the issue? Also this should cout only 2 decimal places right? I'm not allowed to alter the #include and add any fixed setprecision. This is what I have....
Here's an proposal on how to get from point A to point B in zero-gravity without...
Here's an proposal on how to get from point A to point B in zero-gravity without using any propellant and the question why it wouldn't work: A closed tube, filled with water and a round (solid) object. If you need equations, the volume of enclosed water is the same as the round object, but the round object is 10 times lighter. (imagine a glass with water plus a ping-pong ball). On earth the round object will float on the water...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT