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

Matlab can implement the above approximation using a combination of symbolic com

ID: 3550078 • Letter: M

Question

Matlab can implement the above approximation using a combination of symbolic computation

and classical programming:::::


function [ result ,error] = fun( z,a,n )

syms x real;

f=exp(x)*sin(x);


sum=subs(f,'x',a);

prod=1;

for j=1:n

prod=prod*(z-a)/j;

sum=sum+prod*subs(diff(f,x,j),'x',a);

end

result=sum;

error=abs(result-subs(f,'x',z));

end


---------->Explain each line of this program using the Taylor's approximation.


---------->Run the function in a script and print the results for n=1:10, a=0, z= 1 as follows: n f(z) P(z) error [hint: use sprintf to

print the results on the screen or fprintf to a file. Here is an example, run these commands:

str = 'The range for double is: %g to %g and %g to %g';

sprintf(str, -realmax, -realmin, realmin, realmax)


----------->Derive an error bound using max|Rn(x )| and compare it with the actual error derived by the program.

Explanation / Answer

OBJECTIVES Introduce several higher order numerical approximation algorithms that use successive numeric approximations. Introduce the implementation of Newton's Method for approximating the roots of a function. Introduce an implementation of Simpson's Method for approximating the value of an integral. Introduce an implementation of Euler's Method for finding points on the solution function of an ordinary differential equation. There are multiple ways that each of these methods can be implemented in code. In this lab, we have tried to present a clear translation of each algorithm without worrying too much about making our solutions optimal with regard to amount of memory used or total number of computations performed. Also error-checking of the inputs to each function has been left out for brevity in this document. INTRODUCTION Numerical methods are algorithms that approximate the solution of mathematical problems that have solutions which are not conveniently expressed in analytical form (that is, functions such as exponential, sine, etc.). Most real engineering problems do not have convenient analytical solutions. The problems that you study in your engineering courses are often simplified from the real mathematical problem to demonstrate a particular physical principle or to give you a basis upon which to judge a result that you obtain using a numerical method. Perhaps the best example of a successive approximation algorithm is Newton's Method for finding the roots of a function. If you use a numerical method to solve a mathematical problem, be extremely careful that the solution returned by the computer program is in fact a plausible solution to your problem. The adage "garbage in