Skip to content

exp5 #6

Description

@legend17-dot

clear; format long;
x = [0,1,2,3]; y = [1,2,9,28];
h = x(2)-x(1); p = (1.5 - x(1))/h;
n = length(y); diff = y;
for j = 2:n
diff(j:n) = diff(j:n) - diff(j-1:n-1);
end
val = y(1); term = 1;
for j = 1:n-1
term = term*(p-(j-1))/j;
val = val + term*diff(j+1);
end
fprintf('y at x=1.5 = %.8f\n', val);

clc; clear; format long;
x = [0,1,2,3]; y = [1,2,9,28];
h = x(2)-x(1); p = (2.5 - x(end))/h;
n = length(y); diff = y;
for j = 2:n
diff(j:n) = diff(j:n) - diff(j-1:n-1);
end
val = y(end); term = 1;
for j = 1:n-1
term = term*(p+(j-1))/j;
val = val + term*diff(end-j);
end
fprintf('y at x=2.5 = %.8f\n', val);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions