The user inputs a vector containing positive and negative nu
The user inputs a vector containing positive and negative numbers. Separate the vector into four vectors: posEven, negEven, posOdd and negOdd where posEven contains all the even positive numbers, negEven contains all the negative even numbers, posOdd contains all the positive odd numbers and negOdd contains all the negative odd numbers. Assume 0 is posEven [-50 5 6 -71 26 -25 9 -200 0] Write a function named fact to calculate the factorial of a number. The infinite Maclaurin series to calculate the sine of an angle in radians is: sin(x) = x - x^3/3! + x^5/5! - x^7/7! + x^9/9! - ... Write a function, named sine, to calculate the sine of an angle using the above Maclaurin series. Use the fact function created in problem 1 in the sine function. Iterate the terms until the difference between the previous term and the current term is less than 10^-5. Write a program that asks for an angle as the input, passes that angle to the sine function, and displays the result to five decimal places as: The sine of is If 0.3 is entered as the angle, the result would be: The sine of 0.30000 is 0.29552.
Solution
Ansqwer 1.
% input the vector like [-5,10,-10,90]
x = input(prompt);
% in below foure line we are creating empty vecotr
posOdd = [];
posEven = [];
negOdd = [];
negEven = [];
% iterating over all the element in vector
for elm = x
if (elm>=0 && mod(elm,2)==0)
posEven(end+1) = elm
elseif(elm>0 && mod(elm,2) !=0)
posOdd(end+1) = elm
elseif(elm<0 && mod(elm,2) ==0)
negEven(end+1) = elm
elseif(elm<0 && mod(elm,2) !=0)
negOdd(end+1) = elm
end
end
