Vous êtes sur la page 1sur 2

EGME 410 Extra-Credit Homework

Antiderivative of an Arbitrary Function


Due: Thursday, April 26, 2018 by 04:00PM

Problem 1 In Problem 2 of Homework #4, you constructed the antiderivative u(x) of the
3
function e−x on the interval −1 < x < +1, subject to the boundary condition u(−1) = 0.
In this assignment, you will write a Matlab program that constructs the antiderivative
u(x) of an arbitrary function f (x) on an arbitrary interval a < x < b, subject to an arbitrary
boundary condition u(a) = ua .
(a) (+50 points) Write such a Matlab program, with definition similar to the following:
function [u , x ] = antideriv ( fn ,a ,b , ua , tol )

% DESCRIPTION :
% Solves the boundary value problem
% du / dx = f(x), a <x <b
% u(a) = ua
% numerically using a Collocation FEM method
% with linear interpolation

% INPUTS :
% fn - a string giving f(x), e.g., ‘exp (-x .^3) ’
% a - lower boundary
% b - upper boundary
% ua - value at lower boundary : u(a)
% tol - tolerance for convergence

% OUTPUTS :
% u - nodal values of u(x)
% x - nodal values of x

Use linear interpolation of the nodal values, Collocation FEM at the left endpoint of
the element (x = xi ), and the following convergence criterion. The number of elements
used should start at 2, and then double until
|∆ub | < tol, (1)
where ∆ub is the change in u(b) after doubling the number of elements.

1
3
Figure 1: Antiderivative of the function f (x) = e−x on the interval −1 < x < +1 subject to the boundary
condition u(−1) = 0, using a tolerance of tol = 0.05.

(b) (+5 points) Check that your program works correctly by executing the following com-
mands at the command prompt:
>> [u , x ] = antideriv ( ’ exp ( - x .^3) ’ , -1 ,1 ,0 ,0.05);
>> plot (x ,u , ’ - ob ’ );

You should get a plot that is identical (or nearly identical) to Figure 1.
(c) (+10 points) Use your program to find the antiderivative of the function f (x) = sin(x2 )
on the interval −2π < x < 2π. Compare your result to that given by WolframAlpha.

Vous aimerez peut-être aussi