HW #02
Due: 09/13/2023
Note: If you have not registered on the web, your hw paper is NOT graded.
Submission Instructions: (Important! If you do not follow them, your paper is not graded.)



1. Compute


lim
x → ∞ 

xx2 ln (1 + 1

x
)
.


2. It is known that


1

0 
ex2 d x = 1

2


 

π
 
  erf(1)  ∼ 0.746824.
How many partitions are required to achieve this much accuracy for (1) the left-point rectangular rule, (2) the mid-point rectangular rule (Eq.(4) in Lecture #5) and (10) in Lecture #4 the trapezoidal rule ?

Online C compiler
Online Matlab/Octave
Sample C code for the left-point rectangular rule
#include <stdio.h>
#include <math.h>

double f(double x)
 {return 4.0/(1.0+x*x) ; }

int main()
{
 int i, n;
 double a=0.0, b=1.0, h, s=0.0 , x ;
 n=100;
 h = (b-a)/n ;
 for (i= 0;i<n;i++) 
  s = s + f(a + i*h) ;
 s=s*h ;
 printf("Result =%lf\n", s) ;
 return 0;
}
Sample Matlab/Octave code for the left-point rectangular rule
f = @(x) 4/(1+x^2);
a=0;b=1;s=0;
%n=input('Enter n=');
n=100
h=(b-a)/n;
for i=0:1:n-1 
  s=s+f(a+i*h);
end;
s=s*h;
fprintf('%f\n', s);
Sample C code for the trapezoidal rule
/* Trapezoidal rule */
#include <stdio.h>
#include <math.h>

double f(double x)
 {return 4.0/(1.0+x*x);}

int main()
{
 int i, n ;
 double a=0.0, b=1.0 , h, s=0.0, x;
/*
 printf("Enter number of partitions = ");
 scanf("%d", &n) ;
*/
 n=10;
 h = (b-a)/n ;

 for (i=1;i<=n-1;i++) s = s + f(a + i*h);

  s=h/2*(f(a)+f(b))+ h* s;

  printf("%20.12f\n", s) ;
  return 0;
}
Sample MATLAB (Octave) code for the trapezoidal rule
f = @(x) 4/(1+x^2);
a=0;b=1;s=0;
n=10;
%n=input('Enter n=');

h=(b-a)/n;

for i=1:1:n-1 
 s=s+f(a+i*h);
end;

s=h/2*(f(a)+f(b))+h*s;
fprintf('%f\n', s);



File translated from TEX by TTH, version 4.03.
On 13 Sep 2023, 17:29.