{{ message }}

Instantly share code, notes, and snippets.

# Hugo Diaz Norambuena Hugo-Diaz-N

• Delaware, USA
Created Oct 19, 2018
Smoothing Spline Matlab Code (This sparse assembly could be simplified)
View SmoothSpline.m
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
 function [mu,m]=SmoothSpline(X,f,p) % [mu,m]=SmoothSpline(X,f,p) % % This code compute the parameter of "the smoothing natural spline" % for the data (x_i,f_i) with weights {p_i} i.e. the solution of % % \min\Biggl\{ \sum_{i=0}^N p_i\left(\hat{f}(x_i)-f_i \right)^2 % +\int_{a}^{b} \bigl|\hat{f}''(x)\bigr|^2dx \Biggr\} % Input:
Created Oct 19, 2018
Lagrange interpolation with Chebyshev nodes
View ChebyshevInterp.m
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
 function p=ChebyshevInterp(f,n,xx) n = n-1; % Number intervals Xn = cos((pi/(n+1))*(0.5+(0:n))); % Chebyshev Nodes f_X = f(Xn); % f at Chebyshev nodes, omega = BaryWeigths(Xn); % Barycentric Weigths. p = zeros(1,length(xx)); % Setting interpolant is = ismember(xx,Xn); % Position of a member of Xn at xx. p(is) = f(xx(is)); % p(x_k) =f(x_k). xx = setdiff(xx,Xn); % xx \setminus Xn. A = repmat(Xn',1,100);
Created Oct 19, 2018
Rational Root-Finding Method, the approximation in this case is not linear but rational f(x)~ a+b/(x+c) (hypothesis: f'(x_k)*f''(x_k)\neq 0 )
View RationalCode.m
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
 function [flag,xk1] = RationalCode(x0,f,df,d2f,TOL,MaxIt) %[flag,xk] = RationalCode(x0,f,df,d2f,TOL,MaxIt) % % This code approximate a root of f using a rational fuction approx. % Input: % x0 := initial value. % f := function whose roots will be approximated. % df := derivative of f. % d2f := second derivative of f.
Created Oct 19, 2018
Movement particle on a sphere surface under a force F
View position3D.m
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
 % Problem: find u s.t. % \frac{d}{dt}{\bf u}(t)+\alpha {\bf u}(t)\times \frac{d}{dt}{\bf u}(t)&={\bf u}(t)\times {\bf F}(t) % initial position u_0=0.5*\sqrt(2)(0 1 1)^t F=[0 0 10]'; % constant case u0=0.5*sqrt(2)*[0 1 1]'; a=0.1; % alpha in the PDE b=(1/(1+a*a*norm(u0,2)^2)); f=@(t,u) b*(cross(u,F)-a*(F'*u)*u+a*norm(u)^2*F); [t,w]=ode23s(f,[0,10],u0);
Last active Oct 19, 2018
Code to model a spacecraft is given by two 2nd-order equations for the position of the body (x(t), y(t)) --- Numerical Method: Störmer-Verlet (Dual) -- Matlab
View DualVeerlet.m
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
 %---------------- Setting Problem --------------------% x0 = 0.994; % x(0) Initial position y0 = 0.0; % y(0) Initial position dx0 = 0.0; % x'(0) Initial velocity dy0 = -2.031732629557; % y'(0) Initial velocity %-----------------------------------------------------% %---------------- Setting Model ----------------------% mu1 = 0.012277471; % Moon mass, M_m/(M_e+M_m) mu2 = 1-mu1; % Earth mass, M_e/(M_e+M_m) %-----------------------------------------------------%