Scilab
Important Instructions
You are free to use Scilab to check your answers. Please be sure your code is working to your satisfaction before you submit it.
Don't forget to use the 'endfunction' keyword after the function definition.
Do NOT change the name of the function provided under any circumstances. If you change the name of the function, our answer evaluation system will not be able to check your code and you will not be awarded any marks for that question.
Once you press the submit button, you will not be able to modify your code. After submitting your code, we will revert to you with your results in a few working days.
Write your codes in boxes provided below the questions
Here is a sample question and a couple of valid answers to the question: Write a program that takes a vector x as input and returns the same vector, with the order of its elements reversed. For eg. if x = [15; 21; 3; 14], then y should be [14; 3; 21; 15] Here is one valid answer to the question:
function y = reversal(x) len = length(x) for i = 1:len y(i) = x(len-i+1) end endfunction
Here is another valid answer to the question:
function y = reversal(x) y = x($: -1: 1) endfunction
Either one would be considered as a correct answer.
Below are few examples of a wrong answers. (Changing function name, displaying output (instead of returning output, and having code not correctly between function and endfunction are wrong . The order of inputs and outputs for multiple inputs or multiple outputs is also unchangeable.)
function y = reversal(x) something endfunction y = x($: -1: 1)
function y = reversal(x) disp(x($: -1: 1)) endfunction function y = reversl(x) y = x($: -1: 1) endfunction