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

Choice 1 (last name with first letter from A to C): Develop a C-code that numeri

ID: 652867 • Letter: C

Question

Choice 1 (last name with first letter from A to C): Develop a C-code that numerically integrates the following function using N of different values, where N is the number of steps or intervals. Print out all xi,fi =f(xi) and final result. Determine and print the appropriate value of N based on the results for different N values. Integrate the function by using both Trapezoidal rule and Simpson?s rule, then compare the results with it calculated from mathematical software such as Matlab, Mathematica and etc.

Explanation / Answer

#include<stdio.h>
#include<conio.h>
float exp_x(int);
double sin_x(int);
float exp_x(int x)
{
    int i = 1;
    float ex = 1;
    while(i!=0)
    {
     ex+=(float)pow(x,i)/fact(i);
            ++i;
        }
    return ex;
}
double sin_x(int x)
{
    int term=1, j;
    double value=0.0,ang_rad = 0.0;
    ang_rad = ( double ) ang_deg * 3.14 / 180;
    while(term < no_of_terms*2 )
        {
            value +=( double )pow(-1.0,j) * pow(ang_rad,term )/fact( term );
   ++j;
        }
     return value;
}
main()
{
int x,i,j,e;float f;
for(x=1;x<=10;x++)
{
i=x^3;
j=x^2;
f=(0.3*i)+(0.6*j)-(3.2*x)+10;
printf("f(%d)=%f",x,f);
}
for(x=11;x<=20;x++)
{
i=0.2*3.14*x;
f=sin(x)*exp_x(-x);
printf("f(%d)=%f",x,f);
}
getch();
}

_____________________________________________________________________________________
MATLAB
_____________________________________________________________________________________
>>x=1:1:10; f=((0.3*(x^3))+(0.62*(x^2))-(3.2*x)+10);
x=
   7.72   8.48   14.08   26.32   47   77.92   120.88   177.68   250.12   340
  
>>x=11:1:20;f=((sin(0.2*3.14*x))*exp(-x));
_________________________________________________________________________

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote