Skip to content

Commit

Permalink
added splines and integrals
Browse files Browse the repository at this point in the history
  • Loading branch information
rcc02007 committed Nov 8, 2017
1 parent 4ac751b commit 5322aaa
Show file tree
Hide file tree
Showing 17 changed files with 4,190 additions and 0 deletions.
1,439 changes: 1,439 additions & 0 deletions 16_splines/.ipynb_checkpoints/16_splines-checkpoint.ipynb

Large diffs are not rendered by default.

497 changes: 497 additions & 0 deletions 16_splines/.ipynb_checkpoints/lecture 19-checkpoint.ipynb

Large diffs are not rendered by default.

928 changes: 928 additions & 0 deletions 16_splines/16_splines.ipynb

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions 16_splines/Newtint.m
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
Binary file added 16_splines/newton_cotes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 16_splines/octave-workspace
Binary file not shown.
23 changes: 23 additions & 0 deletions 16_splines/simpson3.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function I = simpson3(func,a,b,n,varargin)
% simpson3: composite simpson's 1/3 rule
% I = simpson3(func,a,b,n,pl,p2,...):
% composite trapezoidal rule
% input:
% func = name of function to be integrated
% a, b = integration limits
% n = number of segments (default = 100)
% pl,p2,... = additional parameters used by func
% output:
% I = integral estimate
if nargin<3,error('at least 3 input arguments required'),end
if ~(b>a),error('upper bound must be greater than lower'),end
if nargin<4|isempty(n),n=100;end
x = a; h = (b - a)/n;

xvals=linspace(a,b,n+1);
fvals=func(xvals,varargin{:});
s=fvals(1);
s = s + 4*sum(fvals(2:2:end-1));
s = s + 2*sum(fvals(3:2:end-2));
s = s + fvals(end);
I = (b - a) * s/(3*n);
22 changes: 22 additions & 0 deletions 16_splines/trap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function I = trap(func,a,b,n,varargin)
% trap: composite trapezoidal rule quadrature
% I = trap(func,a,b,n,pl,p2,...):
% composite trapezoidal rule
% input:
% func = name of function to be integrated
% a, b = integration limits
% n = number of segments (default = 100)
% pl,p2,... = additional parameters used by func
% output:
% I = integral estimate
if nargin<3,error('at least 3 input arguments required'),end
if ~(b>a),error('upper bound must be greater than lower'),end
if nargin<4|isempty(n),n=100;end

x = a; h = (b - a)/n;
xvals=linspace(a,b,n);
fvals=func(xvals,varargin{:});
s=func(a,varargin{:});
s = s + 2*sum(fvals(2:n-1));
s = s + func(b,varargin{:});
I = (b - a) * s/(2*n);

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
608 changes: 608 additions & 0 deletions 17_integrals_and_derivatives/17_integrals.ipynb

Large diffs are not rendered by default.

Binary file added 17_integrals_and_derivatives/gauss_weights.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 17_integrals_and_derivatives/octave-workspace
Binary file not shown.
12 changes: 12 additions & 0 deletions 17_integrals_and_derivatives/stainless_steel_psi.jpg.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1.0208494318e-05 1.6556901722
0.00241601032192 33.1999376148
0.00420249682757 53.9506164087
0.00603492155765 82.1777412288
0.00844582763241 114.552704897
0.00959768607462 122.017666367
0.0207793901842 141.840010208
0.0369377352739 161.610673548
0.0574942399989 177.181817537
0.0774314294019 181.959392878
0.100609815751 174.241771174
0.117644389936 156.618719826
Binary file added 17_integrals_and_derivatives/steel_psi.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions 17_integrals_and_derivatives/structural_steel_psi.jpg.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
1.0208494318e-05 1.6556901722
0.00180179924712 23.2370851913
0.00242111456908 34.0306538399
0.00298938741945 36.5170602372
0.00410551613155 38.1670081313
0.0113042060414 39.7537909669
0.026807506079 42.9158720819
0.0450807109082 46.8799580317
0.063896667352 49.1768692533
0.0937667217264 50.5282186886
0.134122601181 48.4475999405
0.194912483429 42.0009357786
0.224198952211 38.3737301413
Binary file added 17_integrals_and_derivatives/trap_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5322aaa

Please sign in to comment.