This is a Linear Algebra assignment I have no programming ex

This is a Linear Algebra assignment. I have no programming experience and I\'m supposed to have this code written.... Pls Help

MATLAB Programming Assignment #2 Taylor Series Approximation of cos (x) Due at the beginning of the lab session during the week of September 26th. Write an app that calculates and displays Taylor series approximations of cos (x) over the range -m x r. The app should allow users to specify the number of terms n to include in the approximation; and the display should plot cos (x) as well as the Taylor series approximation to cos (x) Submit source code and plots that display the approximations that have 1, 2, 3, 5 and 7 terms. Hints The expansion is performed around x·0, so it is a Maclaurin series and has a simple form. You may wishto derive the series for cos (x) from the compact definition of a Taylor series. Alternatively, you can look it up, or deduce it from the pattern implied by the first three terms of the series, which are x2 x4 -21+41 … A somewhat elegant solution can be obtained by implementing a function that calculates the value that an approximation with n terms returns for a specified value of x, i.e. a function that accepts n and x as input parameters, uses n to control the upper limit of a for loop, and returns the value of the series approximation. I do not want to see separate blocks of code for each value of n . To maximize efficiency, you can use symmetry to reduce the total number of computations, i.e., since cos(-x)cos (x), there is no need to calculate cos(-x) after you have calculated cos (x). Personally, I would not bother for such a small problem.

Solution

Taylor Expansion Series of cos x, only using <stdio.h> and without user-defined functions other than int main(), of all angles from -180 to 180 in increments of +5. the following is the code:

#include <stdio.h>
#define PI 3.141592653589
#define NUMBER_OF_TERMS 10

int
main()
{
int cosctr, sinctr;
double ctr, radi;
double cosaccu, costerm, sinaccu, sinterm;

for (ctr = -180; ctr < 185; ctr = ctr + 5) {
radi = ctr * PI/180.0;
cosctr = 1;
cosaccu = 1;
costerm = 1;
sinctr = 2;
sinaccu = radi;
sinterm = radi;
while (cosctr <= 2*NUMBER_OF_TERMS) {
costerm = costerm*(-1)*(radi*radi)/(cosctr*(cosctr + 1));
cosaccu = cosaccu + costerm;
cosctr+=2;
} do {
sinterm = sinterm*(-1)*(radi*radi)/(sinctr*(sinctr + 1));
sinaccu = sinaccu + sinterm;
sinctr+=2;
} while (sinctr <= 2*NUMBER_OF_TERMS);
printf(\"%.2lf %.12lf %.12lf %.12lf\ \", ctr, radi, cosaccu, sinaccu);
} return 0;
}

The code above is accurate for a 15 terms expansion approximation. however, if I change NUMBER_OF_TERMS to, for example, 5 or 10, the approximation is flawed.

The key to high precession, yet simple calculation of sind(degrees) and cosd(degrees) is to reduce the range of degree to 0 to 90 first (or even 0 to 45), using the usual trigonometric adjustments with degree arrangements first.

Reductions:
angle = fmod(angle, 360) // reduce (-360..360) or use a = a - (int)(a/360)
sin(x) = -sin(-x) // reduce to [0..360)
cos(x) = cos(-x) // reduce to [0..360)
sin(x) = -sin(x-180) // reduce to [0..180)
cos(x) = -cos(x-180) // reduce to [0..180)
sin(x) = cos(90-x) // reduce to [0..90)
Further reductions:
For [45-90) use sin(x) = cos(90-x) // reduce to [0..45)

then convert to radians and use Taylor series expansion.

This is a Linear Algebra assignment. I have no programming experience and I\'m supposed to have this code written.... Pls Help MATLAB Programming Assignment #2
This is a Linear Algebra assignment. I have no programming experience and I\'m supposed to have this code written.... Pls Help MATLAB Programming Assignment #2

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site