Question

Write a MATLAB program that implements the Insertion Sort algorithm. Test your implementation with this set...

Write a MATLAB program that implements the Insertion Sort algorithm. Test your implementation with this set of inputs: 16.2 32.7 -0.5 4.4 21.8 -17.0 6.9 14.1 1.5.

Homework Answers

Answer #1
v = input("Enter a vector of numbers: ");
for i=2:length(v)
    for j=i:-1:2
        if v(j) < v(j-1)
            temp = v(j);
            v(j) = v(j-1);
            v(j-1) = temp;
        end
    end
end
fprintf("Sorted vector is\n")
disp(v)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program to implement bubble sort, insertion sort, selection sort, merge sort and quick sort...
Write a program to implement bubble sort, insertion sort, selection sort, merge sort and quick sort (pivot = first index) algorithms. Compute the CPU processing time for all the algorithms for varying input sizes as follows: N = 102, 103, 104, 105, and 106 Use a random number generator to generate the inputs. Obtain the inputs from the following input ranges: 1- 103, 1 - 106, 1 – 109, 1 - 1012 Write down your results as a table (with...
Q) Write a computer program to test the stability of any continuous-time LTI system.( using Matlab)...
Q) Write a computer program to test the stability of any continuous-time LTI system.( using Matlab) Test your program on the impulse response.   h(t)= e^(-2t) u(t) Attached the program (Matlab) file and a screen shot of the results.
Write a code in c++ using linear insertion following the steps below. Comment your work. 1....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1.    Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program. 2.     You can use a statically-allocated one-dimensional array of doubles for this with length 100. You...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
c++ Program Description You are going to write a computer program/prototype to process mail packages that...
c++ Program Description You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list....
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics relating to data supplied by the user. The program will ask the user to enter the number of items making up the data. It will then ask the user to enter data items one by one. It will store the data items in a double array. Then it will perform a number of statistical operations on the data. Finally, it will display a report...