forked from sed12008/ME3255S2017
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
2,569 additions
and
193 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
function yint = Newtint_bak(x,y,xx) | ||
% Newtint: Newton interpolating polynomial | ||
% yint = Newtint(x,y,xx): Uses an (n - 1)-order Newton | ||
% interpolating polynomial based on n data points (x, y) | ||
% to determine a value of the dependent variable (yint) | ||
% at a given value of the independent variable, xx. | ||
% input: | ||
% x = independent variable | ||
% y = dependent variable | ||
% xx = value of independent variable at which | ||
% interpolation is calculated | ||
% output: | ||
% yint = interpolated value of dependent variable | ||
|
||
% compute the finite divided differences in the form of a | ||
% difference table | ||
n = length(x); | ||
if length(y)~=n, error('x and y must be same length'); end | ||
b = zeros(n,n); | ||
% assign dependent variables to the first column of b. | ||
b(:,1) = y(:); % the (:) ensures that y is a column vector. | ||
for j = 2:n | ||
for i = 1:n-j+1 | ||
b(i,j) = (b(i+1,j-1)-b(i,j-1))/(x(i+j-1)-x(i)); | ||
end | ||
end | ||
% use the finite divided differences to interpolate | ||
xt = 1; | ||
yint = b(1,1); | ||
for j = 1:n-1 | ||
xt = xt*(xx-x(j)); | ||
yint = yint+b(1,j+1)*xt; | ||
end | ||
function yint = Newtint(x,y,xx) | ||
% Newtint: Newton interpolating polynomial | ||
% yint = Newtint(x,y,xx): Uses an (n - 1)-order Newton | ||
% interpolating polynomial based on n data points (x, y) | ||
% to determine a value of the dependent variable (yint) | ||
% at a given value of the independent variable, xx. | ||
% input: | ||
% x = independent variable | ||
% y = dependent variable | ||
% xx = value of independent variable at which | ||
% interpolation is calculated | ||
% output: | ||
% yint = interpolated value of dependent variable | ||
|
||
% compute the finite divided differences in the form of a | ||
% difference table | ||
n = length(x); | ||
if length(y)~=n, error('x and y must be same length'); end | ||
b = zeros(n,n); | ||
% assign dependent variables to the first column of b. | ||
b(:,1) = y(:); % the (:) ensures that y is a column vector. | ||
for j = 2:n | ||
for i = 1:n-j+1 | ||
b(i,j) = (b(i+1,j-1)-b(i,j-1))/(x(i+j-1)-x(i)); | ||
end | ||
end | ||
%b | ||
% use the finite divided differences to interpolate | ||
xt = 1; | ||
yint = b(1,1); | ||
for j = 1:n-1 | ||
xt = xt*(xx-x(j)); | ||
yint = yint+b(1,j+1)*xt; | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
497 changes: 497 additions & 0 deletions
497
lecture_19/.ipynb_checkpoints/lecture 19-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
function yint = Newtint(x,y,xx) | ||
% Newtint: Newton interpolating polynomial | ||
% yint = Newtint(x,y,xx): Uses an (n - 1)-order Newton | ||
% interpolating polynomial based on n data points (x, y) | ||
% to determine a value of the dependent variable (yint) | ||
% at a given value of the independent variable, xx. | ||
% input: | ||
% x = independent variable | ||
% y = dependent variable | ||
% xx = value of independent variable at which | ||
% interpolation is calculated | ||
% output: | ||
% yint = interpolated value of dependent variable | ||
|
||
% compute the finite divided differences in the form of a | ||
% difference table | ||
n = length(x); | ||
if length(y)~=n, error('x and y must be same length'); end | ||
b = zeros(n,n); | ||
% assign dependent variables to the first column of b. | ||
b(:,1) = y(:); % the (:) ensures that y is a column vector. | ||
for j = 2:n | ||
for i = 1:n-j+1 | ||
b(i,j) = (b(i+1,j-1)-b(i,j-1))/(x(i+j-1)-x(i)); | ||
end | ||
end | ||
%b | ||
% use the finite divided differences to interpolate | ||
xt = 1; | ||
yint = b(1,1); | ||
for j = 1:n-1 | ||
xt = xt*(xx-x(j)); | ||
yint = yint+b(1,j+1)*xt; | ||
end |
Oops, something went wrong.