Given the information below, how do you write the code according to the terms be
ID: 3109357 • Letter: G
Question
Given the information below, how do you write the code according to the terms below? The values for sin(x) and cos(x), where x is the angle in radians, can be approximated using the appropriate series shown below. The more terms you include in the series the more accurate your answers should be. sin(x) = x middot Product_n=1^infinity (1-x^2/n^2 pi^2) = x middot (1-x^2/1^2 pi^2)(1 - x^2/2^2 pi^2)(1 - x^2/2^2 pi^2)(1 - x^2/3^2 pi^2).... cos(x) = Product_n=1^infinity (1-4x^2/(2n-1)^2 pi^2) = (1-4x^2/1^2pi^2)(1-4X^2/3^2 pi^2)(1-4x^2/5^2 pi^2)...Explanation / Answer
clc;
clear all;
close all;
format long
n=input('Enter the Angle in degree ');
x=n*pi/180; %%%% conversion in radians
fprintf('The Angle = %f degree',n);
fprintf(' ');
fprintf('The Angle = %f radians',x);
fprintf(' ');
%%%% for sin series %%%%%
sum=x;
for j=1:300
sum=sum*(1-x^2/(j^2*pi^2));
end
act_=sin(x);
fprintf('The sin x according to series after 300 iteration is = %f',sum);
fprintf(' ');
fprintf('The sin x according to intrinsic function is = %f',act_);
fprintf(' ');
% % % % cos x series %%%%
c_sum(1,1)=0;
c_sum(1,2)=1;
k=1;
while ( abs(c_sum(1,1)-c_sum(1,2)) > 0.000001)
c_sum(1,1)=c_sum(1,2);
c_sum(1,2)=c_sum(1,2)*(1-4*x^2/((2*k-1)^2*pi^2));
k=k+1;
end
act_=cos(x);
fprintf('The cos x according to series after %d iteration is = %f',k, c_sum(1,2));
fprintf(' ');
fprintf('The cos x according to intrinsic function is = %f',act_);
fprintf(' ');
Output:
Enter the Angle in degree 30
The Angle = 30.000000 degree
The Angle = 0.523599 radians
The sin x according to series after 300 iteration is = 0.500046
The sin x according to intrinsic function is = 0.500000
The cos x according to series after 157 iteration is = 0.866180
The cos x according to intrinsic function is = 0.866025
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.