Numerical Analysis Algorithm: Calculating Cosine using Taylor Series, Assignments of Assembly Language Programming

assemblly language programming. For computer Engineering students.

Typology: Assignments

2019/2020

Uploaded on 09/20/2020

unknown user
unknown user 🇬🇪

5 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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.
[Lab Assignment #6, Part 2]
[Numerical Analysis Algorithm – Calculate value of Cosine using
Taylor Series]
COMPE-160
Emrashvili Luka 823355800
pf3
pf4
pf5
pf8

Partial preview of the text

Download Numerical Analysis Algorithm: Calculating Cosine using Taylor Series and more Assignments Assembly Language Programming in PDF only on Docsity!

 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.

[Lab Assignment #6, Part 2]

[Numerical Analysis Algorithm – Calculate value of Cosine using Taylor Series]

COMPE-

Emrashvili Luka 823355800

1. Description of the Problem / Method:

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.

2. Pseudocode:

FUNCTION Concert to convert radians in the interval [-2 π; 2 π]

Input double x; Define result by value of x;

IF result is less than -2 π

WHILE result is less than -2 π

Increase result by 2 π

WHILEEND

ELSE WHILE result is more than 2 π

Decrease result by 2 π

WHILEEND

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

3. C-code:

#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; }

4. Screen capture of the code and the resulting display(s):

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)); }