Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Numerical analysis Lab 3 Required: 1. Include comments in your code giving your

ID: 3750553 • Letter: N

Question

Numerical analysis Lab 3

Required: 1. Include comments in your code giving your name, the date, and a code description 2. Also include comments in your Output.doc/x that give the corresponding problem number. 3. Whenever printing a value to the screen, also print a statement defining the value and any units. Example: Do "the distance x is 23 meters"; Don't "23" Problem 1 40 Factorial is the product of an integer and all the integers below it: r! - (x) *(x-1) * (x-2)21-i Write both C and Matlab scripts that accept inputs for the value of r and then prints the value of x!. Note that 0! = 1. First solve this problem using a for or while loop. Then solve it using recursion. These methods may be included in a single script. Print both outputs Problem 2 50 The trigonometric functions sin and cos can be approximated using power series expansions These expansions are accurate over a limited range with increasing error as the input moves away from zero. The series for cosine is: cos(a) 1- (-1)i r2i (2i)! Write both C and Matlab scripts that accept inputs for the value of x and the number of terms in the series and then prints the value of cos(). You may use one of your factorial methods generated in the problem above. Note that 13! produces a value beyond INT MAX First solve this problem using a for or while loop. Then solve it using recursion. These methods may be included in a single script. Print both outputs.

Explanation / Answer

As the part to answer was not given, as per the chegg policy, answer to part 1 is being provided:

C Script:

//==========================

#include<stdio.h>

int main()
{
    int x,i,fact_for=1,fact_while=1;
    printf(" Enter the value of x: ");
    scanf("%d",&x);
    for(i=x;i>=1;i=i-1)
    {
      fact_for = fact_for * i;
    }
    i=x;
    while(i>=1)
    {
      fact_while = fact_while * i;
      i=i-1;
    }
    printf("factorial by for loop = %d , while loop = %d",fact_for,fact_while);
    system("PAUSE");
    return 1;
}

//==========================

MATLAB script:

%===============================================

clear all;
clc;
fact_for=1;
fact_while=1;
x=input(' Enter the value of x: ');
for i=x:-1:1
fact_for = fact_for * i;
end
i=x;
while(i>=1)
fact_while = fact_while * i;
i=i-1;
end
fprintf('factorial by for loop = %d , while loop = %d ',fact_for,fact_while);

%===============================================

Hope this helps! In case of any clarification, please comment!