This problem is done with matlab this problem has to be done
This problem is done with matlab
(this problem has to be done using loops and maybe if statements, nothing else)
function s = prob3_2(x,N)
?
end
test case to to test function x = 0.2; N = 7; -> s = 0.198669330795061
(10) The value of sin(x) (x in radians) can be approximated by the alternating series 3 5 7 xXx sin(x) = x- sin(x) - x- + 31 + Create a function (prob3_2) that takes inputs of a scalar angle measure (in radians) and the number of approximation terms, N, and estimates sin(x). Do not use the SIN function in your solution. You may use the FACTORIAL function.Solution
Matlab code for sin series
Method 1:
% SINESERIES: computes sin(x) from series expansion.
% A script to evaluate the series expansion of sine with the formula:
% sin(x) = x-(x^3/3!)+(x^5/5!)-...
x = input(\'Enter the argument x: \');
n = input(\'Enter the interval n: \');
N = 1:1:n; % Creates row vector with n elements, 1 at a time.
k = 2*N-1; % For convenience with prod() function
j = N-1; % For cleanup.
sinseries = ((-1).^(j)).*((x.^(k))./(prod(k)))
sum(sinseries)
end
Method 2:
function y = sin2(x)
n = 1 : 100;
c = 2*n-1;
s = (-1).^(n-1);
f = factorial(c);
for i = 1 : length(x)
y(i) = sum(s .* x(i).^c ./ f);
end
