Malab Help!!

edited May 2008 in Science & Tech
I am new with matlab and I am very confused on how to write this. Can anyone help.

1. Write the following MATLAB function
function [C,X, Y ] = Chebyshev (func, N, a, b)
to construct and evaluate an interpolating polynomial of degree N for f(x) over [a, b], with the zeros of the Chebyshev polynomial of degree N + 1 as nodes.

Inputs: func - the string function to be approximated
a - left end point
b - right end point
N - the degree of the interpolating polynomial

Outputs: C - the vector containing the coefficients of the interpolating polynomial
X - the abscissa vector
Y - the ordinate vector
The results are to be in this format:
Tables for the results
x f(x) y f(x) − y
0.5
0.8
0.9
0.99

Data and Results for Problem # 1
1. f(x) = ln(x + 3) over [−1, 1]
N = 3
2. f(x) = sin x + cos x over [−1, 1]
N = 2
3. f(x) = cos x over [−1, 1].
N = 2

Comments

  • edited May 2008
    So far this is what i did but i dont know how to call a function, can anyone help?
    function [C,X,Y] = Chebyshev( func, N, a, b )

    X=(b+a-(b-a)*cos((2*(0:N-1)+1)*pi/(2*N)))/2;
    Y = eval(func,X);

    C=zeros(1,N+1);


    call function as
    [C,X,Y] = Chebyshev( , 2, -1, 1)
Sign In or Register to comment.