Info

This question is closed. Reopen it to edit or answer.

Need some help with these pracs

1 view (last 30 days)
Hong
Hong on 28 Jul 2015
Closed: John D'Errico on 20 Jun 2022
1. Write a function called int_col that has one input argument, a positive integer n that is greater than 1, and one output argument v that is a column vector of length n containing all the positive integers smaller than or equal to n, arranged in such a way that no element of the vector equals its own index. In other words, v(k) is not equal to k for any valid index k.
2.Write a function called hulk that takes a row vector v as an input and returns a matrix H whose first column consist of the elements of v, whose second column consists of the squares of the elements of v, and whose third column consists of the cubes of the elements v. For example, if you call the function likes this, A = hulk(1:3) , then A will be [ 1 1 1; 2 4 8; 3 9 27 ].
I can understand what the questions ask me to do, but I just dont have a clue how to start these two Qs. if any one can help me, even just the ideas how to approach these, I will be grateful. thanks
  3 Comments
Jan
Jan on 17 Jun 2022
@Adwaith G: Or maybe a little bit simpler:
H = v(:) .^ (1:3);
Jan
Jan on 20 Jun 2022
@Jeffrey Clark: This is neither valid Matlab syntax nor do I see the connection to the question.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!