




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
assemblly language programming. For computer Engineering students.
Typology: Assignments
Uploaded on 09/20/2020
5 documents
1 / 8
This page cannot be seen from the preview
Don't miss anything!





I declare that all material in this assignment is my own work except where there is clear reference to the work of others. I have read, understood and agree to the SDSU Policy on Plagiarism and Cheating on the university website at http://go.sdsu.edu/student_affairs/srr/cheating-plagiarism.aspx and the syllabus for the consequences of plagiarism, including both academic and punitive sanctions.
Remark*. By submitting this assignment report electronically, you are deemed to have signed the declaration above.
[Numerical Analysis Algorithm – Calculate value of Cosine using Taylor Series]
In this programming assignment, we have to create a numerical analysis algorithm. I have chosen computing the value of cosine function using Taylor Series. There are several steps in this program. We had to select, define and test a numerical algorithm using a spreadsheet, write a pseudocode version for the algorithm, implement it as an C code and test the algorithm with a minimum of 50 test cases including extremes and invalid inputs.
Input double x; Define result by value of x;
Return result FUNCTIONEND FUNCTION Calc_Fact to calculate factorial Input: int x IF x is not equal to 0, FOR iteration bounds [1; x] Multiply result by iterator FOREND
#include <stdio.h> #include <stdlib.h> #include <math.h> double Convert (double x) { double result = x; if (result <= -6.2831853) { while (result <= -6.2831853) result += 6.2831853; } else { while (result >= 6.2831853) result -= 6.2831853; } return result; } double Calc_Fact(int x){ int j; double fact = 1.0; if (x != 0){ for (j = 1; j <= x; ++j) fact = j; return fact; } else return 1.0; } double cosine (double x){ double result = 1.0; double NewTerm = 1.0; double Certanity = 1.0; int k = 1; int j; while (Certanity >= 0.0000001){ for (j = 1; j <= 2k; j++) NewTerm *= x; NewTerm /= Calc_Fact (2 * k); if (k % 2 == 1) result -= NewTerm; else result += NewTerm;
Certanity = NewTerm; NewTerm = 1.0; k++; } return result; } int main () { double angle, cResult; printf("Enter the angle in radians: "); scanf("%lf", &angle); int j; for (j = 0; j <= 25; ++j){ printf ("The value of cosine of %lf radians in C is %lf\n", angle + j, cos (angle + j)); angle = Convert (angle + j); printf("The value of calculated cosine is %lf\n", cosine(angle)); } return 0; }
Edited part: int j; for (j = 0; j <= 25; ++j){ printf ("The value of cosine of %lf radians in C is %lf\n", angle - j, cos (angle - j)); angle = Convert (angle - j); printf("The value of calculated cosine is %lf\n", cosine(angle)); }