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: |
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); |
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. |
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); |
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) | |
%-----------------------------------------------------% |