julianne
31 Jan 2007, 12:07am
I have been trying to write a matlab function that will evaluate the taylor series of the ln(x) with the base point at x=1. then I need to use that taylor series to to evaluate the approximate value of f (x) for 0 ≤ x ≤ 2 when the Taylor series is truncated at two,three, and four terms. Perform these evaluations with a function m-file named taylor.m that is vectorized such that its input is an array of x values, and its output is the series value at each x for a specified series length. In other words if x = [0 : 0.02 : 2], then the
function taylor (x, N ) should give a vector whose elements are the value of the Taylor series truncated at N terms when it is evaluated at each element of x.
I have gotten started but keep getting error messages...and I don't know what is going wrong!
so far I have
function f=taylor(x,N)
%evaluate the taylor series for any function (specifically ln(x) for the
%homework problem)
n=[0:0.02:2];
%relative to x0=1
terms=(-1).^(j/2).*(x-1).^n./factorial(n);
f=sum(terms)
but am getting errors with the factorial..can anyone offer any help??
function taylor (x, N ) should give a vector whose elements are the value of the Taylor series truncated at N terms when it is evaluated at each element of x.
I have gotten started but keep getting error messages...and I don't know what is going wrong!
so far I have
function f=taylor(x,N)
%evaluate the taylor series for any function (specifically ln(x) for the
%homework problem)
n=[0:0.02:2];
%relative to x0=1
terms=(-1).^(j/2).*(x-1).^n./factorial(n);
f=sum(terms)
but am getting errors with the factorial..can anyone offer any help??