Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Comparison
- #As mentioned in Holmes, cubic B-splines reduce the problem down to having to solve for (approximately) n unknowns.
- #The advantage of B-splines is that they are easier to code.
- #This procedure is faster than the algorithm presented in the pre-class work, and requires
- #minimal storage, which means finding the coefficients for a cubic spline is
- #fairly easy even for a large number of interpolation points.
- #They are also very useful for least squares fitting of data,
- #as well when solving differential equations numerically [Holmes, 20016].
- #The only problem that can present is that if the matrix A is not invertible, the algorithm will not converge.
- #The algorithm presented in the pre class work is easy to understand since is based on the primary conditions
- #and assumptions of the theory. However, this hard-coded algorithm is just for input vectors of size 3.
- #Time and space complexity will depend on the functions to solve.
- function k= B_cubic(x0, y0)
- #We will use the same assumptions presented in the Assignment, also considering that h=1.
- #We will conside the form: Ck = z
- C = []; # coefficients of k
- z = []; #
- n = size(x0)(1);
- for i = 1:(n-2)
- disp(i);
- #d: equation derived equation for the unknown ks in terms of the known ys.
- Y = [Y; 6.* (y0(i+2)-2.* y0(i+1) - y0(i))];
- #appending the rows
- c = zeros(1, n);
- c(i) = 1;
- c(i+1) = 4;
- c(i+2) = 1;
- C = [C; c];
- endfor
- #as mentioned before, we are considering the natural spline conditions k1=kn=0
- Y = [0; Y; 0];
- c = zeros(1,n);
- c(1) = 1;
- C = [c; C];
- c = zeros(1,n);
- c(n) = 1;
- C = [C; c];
- #Obtaining the values of ks
- k = C^(-1)*z;
- return
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement