Question

8. Write a function which reverses a vector, i.e. if the input is (4, 2, 1,5,-3], the output would be [-3,5, 1, 2,4]. 9. Writ i need this done in Matlab
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

COMMAND WINDOW inp_vector 1 2 345 >> reverse (inp_vector) ans 5 4 3 21\

function [ out-vector reverse( inp-vector ) %function named reverse which takes in a vector as an argument and rreturns the

function [ out_vector ] = reverse( inp_vector ) %function named reverse which takes in a vector as an argument and rreturns the reversed vector.

out_vector = fliplr(inp_vector); % here we are using the builtin function of matlab to reverse the vector provided by the user.

end

2.

function [ s ] = vec. Sum( vec ) s = sum(vec(2:2:length(vec))); end %this line of code will sum the every second element of t>vec [1, 2, 3, 4, 5] vec - 1 2 345 >> vec sum( vec) ans fi

function [ s ] = vec_sum( vec )

s = sum(vec(2:2:length(vec))); %this line of code will sum the every second element of the vector.

end

Thank You.

For help please comment.

Add a comment
Know the answer?
Add Answer to:
i need this done in Matlab 8. Write a function which reverses a vector, i.e. if...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as...

    Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...

  • Note: I need matlab code and it must be on first entry, output what the question...

    Note: I need matlab code and it must be on first entry, output what the question needs and i need it without any false in the matlab pls program logic: • Find the index of minimum element with min() function. Make sure to take two outputs while using min(), the second output is the location of the minimum element. • replace the element at minimum index with mean(v) • find sum(v) and assign it to output program: function x =...

  • What would the function look like in MATLAB? Write a function called mysort that takes a...

    What would the function look like in MATLAB? Write a function called mysort that takes a 3-element vector as its sole arguments. It uses if statements, possibly nested, to return a 3-element vector with its elements in non-decreasing order, i.e., the first element in the returned vector equals the smallest element of the input vector and the last element equals the largest element in the input vector. NOTE: Your function should not use any built-in functions, e.g., sort, min, max,...

  • [MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a...

    [MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a vector. The cumulative product, pj, of the jth element of the vector x, xj, is defined by pj = (x1)(x2) … (xj) for j = 1:length of the vector x. DO NOT USE CUMPROD For example, when you run your function it should look like this: >> x = [2 3 4 2]; >> myMultProd(x) >> ans = 2 6 24 48 That is,...

  • MATLAB HELP PLEASE Write a Matlab function that evaluates a sum of sines at a set...

    MATLAB HELP PLEASE Write a Matlab function that evaluates a sum of sines at a set of points. The first term is just a constant (a coefficient with no sine term). Then, each sine term will have a coefficient before it and then an increasing multiple of the angle inside. For example, consider the sum 3 + 4 sin(9)-1.5 sin (20) 2 sin (40)3 sin (50) We recognize that this is the same as 344sin(101+-1.5 sin (20) + 0 sin...

  • MATLAB: write a function that retuns logical true of vector or matrics or scaler is empty...

    MATLAB: write a function that retuns logical true of vector or matrics or scaler is empty Write a function that retuns logical true of vector or matrics or scaler is empty %% P2: Check for an empty matrix % Write a function myIsEmpty which takes one input (scalar, vector, matrix, ...) % and returns logical true if the input is empty and false otherwise. % DO NOT USE MATLAB's isempty FUNCTION! % % Example: An input of [] should result...

  • write it in matlab language Question No 4 6 Marks The surface area and volume of...

    write it in matlab language Question No 4 6 Marks The surface area and volume of the shown ring-shaped mechanical part are calculated respectively as follows: A =rd (2k +d) V = *d? (2R +d) Write a user defined function that computes surface area (A) and volume (V) of this ring from the arguments d and R. Suppose that is constrained to be 15 in, greater than d. Write a script file that uses your function to plot A and...

  • MATLAB QUESTION Write a MATLAB function called vector_input that takes no inputs and returns no outputs. Instead, when c...

    MATLAB QUESTION Write a MATLAB function called vector_input that takes no inputs and returns no outputs. Instead, when called, it gives control to the user and asks the user to input a length-3 vector. Then the function prints: The sum of ___, ____, and ____ is ____. [new line] where the first three blanks are filled by each element in input vector, and the last blank is the sum of all three elements.

  • Using matlab Write a function that receives a vector as an input argument and prints the...

    Using matlab Write a function that receives a vector as an input argument and prints the individual elements from the vector in a sentence format. One example of calling this function on the command window looks like >>printvec([1.12 23 9.245]) Element 1 is 1.12 Element 2 is 23.00 Element 3 is 9.25 1. (Note: your function should work for any vector.)

  • please solve in matlab 1[35p) Write a user-defined MATLAB function that determines the unit vector in...

    please solve in matlab 1[35p) Write a user-defined MATLAB function that determines the unit vector in the direction of the line that connects two points (A and B) in space. For the func- tion name and arguments, use n = unitvec (A,B). The input to the function are two vectors A and B, each with the Cartesian coordinates of the corre- sponding point. The output is a vector with the components of the unit vector Join the direction from A...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT