Exp-03 Matlab

5
Course No: EEE 212 Experiment No: 03 Name of the experiment: INTERPOLATION Name: Md. Arifur Rahman Date of performance: 11-03-2015 Student ID: 1206130 Date of submission: 18-03-2015 Department: EEE Level 2 / Term 2 Section: B ( B-2 ) Partner’s ID: 1206121 Group No:15

description

Matlab essentials

Transcript of Exp-03 Matlab

  • Course No: EEE 212

    Experiment No: 03

    Name of the experiment:

    INTERPOLATION

    Name: Md. Arifur Rahman

    Date of performance: 11-03-2015 Student ID: 1206130

    Date of submission: 18-03-2015 Department: EEE

    Level 2 / Term 2

    Section: B ( B-2 )

    Partners ID: 1206121

    Group No:15

  • EXERCISE 2 -

    Plot the curve corresponding to the following table using linear Interpolation.

    x f(x)

    0 0

    1 0.8415 2 0.9093

    3 0.1411

    4 -0.7568

    5 -0.9589

    6 -0.2794

    Solution % given data points

    x = [0 1 2 3 4 5 6];

    y = [0 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794];

    plot(x,y,'ko'), hold;

    for i=1:length(x)-1

    X(1) = x(i);

    X(2) = x(i+1);

    sum = poly(x(i+1))*y(i)/(x(i)-x(i+1)) -

    poly(x(i))*y(i+1)/(x(i)-x(i+1));

    % selecting two element

    matrix p=polyval(sum, X);

    plot(X,p), grid on, hold on;

    end

  • EXERCISE 3 y = sin x; x = 0:10, x = 0:0.25:10; construct the interpolant y and plot.

    Solution clear all;

    close

    all; clc;

    % creating the data points from given

    function. x1 = 0:10;

    x2 = 0:0.25:10;

    y1 = sin(x1);

    y2 = sin(x2);

    % marking the data points on plot.

    subplot(2,1,1),plot(x1,y1,'o'), hold on;

    subplot(2,1,2),plot(x2,y2,'o'), hold on;

    % Interpolation for x1 and y1.

    for i=1:length(x1)-1

    X1(1) = x1(i);

    X1(2) = x1(i+1);

    sum1 = poly(x1(i+1))*y1(i)/(x1(i)-x1(i+1))

    - poly(x1(i))*y1(i+1)/(x1(i)-x1(i+1));

    p1=polyval(sum1, X1);

    subplot(2,1,1), plot(X1,p1), title('Linear Interpolation for x

    = 0:10'), grid on, hold on; end

  • % Interpolation for x2 and y2. for i=1:length(x2)-1

    X2(1) = x2(i);

    X2(2) = x2(i+1);

    sum2 = poly(x2(i+1))*y2(i)/(x2(i)-x2(i+1))

    - poly(x2(i))*y2(i+1)/(x2(i)-x2(i+1));

    p2=polyval(sum2, X2);

    subplot(2,1,2), plot(X2,p2), title('Linear Interpolation for x

    = 0:0.25:10'), grid on, hold on; end

    Plot: