initial version
This commit is contained in:
commit
8e602ca6bf
26 changed files with 3306 additions and 0 deletions
6
FittingAndMath/CatStructFields.m
Normal file
6
FittingAndMath/CatStructFields.m
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
function S = CatStructFields(S, T, dim)
|
||||
fields = fieldnames(S);
|
||||
for k = 1:numel(fields)
|
||||
aField = fields{k}; % EDIT: changed to {}
|
||||
S.(aField) = cat(dim, S.(aField), T.(aField));
|
||||
end
|
||||
37
FittingAndMath/Vector1stOrderDE.m
Normal file
37
FittingAndMath/Vector1stOrderDE.m
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
function xt = Vector1stOrderDE(A,x0,t)
|
||||
%Vector1stOrderDE: - solves the vector equation dx/dt=Ax
|
||||
|
||||
%inputs: A - matrix of the equation, x0 - x for t=0, t - time axis to
|
||||
%evaluate values at. derivation is given at:
|
||||
%https://www.unf.edu/~mzhan/chapter4.pdf
|
||||
|
||||
%Yair Judkovsky, 3.10.2020
|
||||
|
||||
if nargin==0
|
||||
A=[.1,.01;-.002,-.002].*i;
|
||||
x0=[.3,0.0001];
|
||||
t=linspace(0,100,100000);
|
||||
end
|
||||
nt=length(t);
|
||||
if any(~isfinite(A(:))), xt = 123.123; return, end
|
||||
[ev,lam]=eig(A);
|
||||
nev=length(diag(lam));
|
||||
phi0i=inv(ev);
|
||||
% add singleton dimension as the first (time) index and replicate
|
||||
% eigenvectors along that dimension.
|
||||
evp=repmat(reshape(ev,[1,nev,nev]),[length(t),1,1]);
|
||||
|
||||
lamt=reshape(exp(diag(lam)*t).',length(t),1,nev);
|
||||
lamt=repmat(lamt,1,nev,1);
|
||||
phit=lamt.*evp;
|
||||
|
||||
xt=reshape(reshape(phit,nev*nt,nev)*(phi0i*x0),nt,nev);
|
||||
|
||||
if nargin==0
|
||||
figure;
|
||||
plot(xt);
|
||||
hold on
|
||||
plot(real(x0),imag(x0),'o');
|
||||
axis equal
|
||||
end
|
||||
|
||||
45
FittingAndMath/fit_linear.m
Normal file
45
FittingAndMath/fit_linear.m
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
function [a,b,da,db]=fit_linear(x,y,varargin)
|
||||
%fit_linear: 1st order linear regression.
|
||||
|
||||
%This function fits a dataset of x and y values to the linear equation
|
||||
%y=ax+b. it is optional for the user to insert also y error values for the
|
||||
%estimation of a and b errors.
|
||||
%
|
||||
|
||||
%Yair Judkovsky, 21.8.2013
|
||||
|
||||
if nargin==2 %case of no error input - assuming that all errors are equal
|
||||
dy = ones(size(y));
|
||||
else
|
||||
dy = varargin{1};
|
||||
end
|
||||
|
||||
dy2=dy.^2;
|
||||
x2=x.^2;
|
||||
xy=x.*y;
|
||||
|
||||
S=sum(1./dy2);
|
||||
Sx=sum(x./dy2);
|
||||
Sy=sum(y./dy2);
|
||||
Sxx=sum(x2./dy2);
|
||||
Sxy=sum(xy./dy2);
|
||||
D=S*Sxx-Sx^2;
|
||||
|
||||
a=(S*Sxy-Sx*Sy)/D;
|
||||
b=(Sxx*Sy-Sxy*Sx)/D;
|
||||
|
||||
if nargin==2 %no error given - need to estimate it
|
||||
Ytheo=a*x+b;
|
||||
dy2=mean((Ytheo-y).^2)*ones(size(y));
|
||||
S=sum(1./dy2);
|
||||
Sx=sum(x./dy2);
|
||||
Sxx=sum(x2./dy2);
|
||||
D=S*Sxx-Sx^2;
|
||||
da=sqrt(S/D);
|
||||
db=sqrt(Sxx/D);
|
||||
else
|
||||
da=sqrt(S/D);
|
||||
db=sqrt(Sxx/D);
|
||||
end
|
||||
|
||||
return
|
||||
9
FittingAndMath/horizontal.m
Normal file
9
FittingAndMath/horizontal.m
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function horzvec=horizontal(vec)
|
||||
%reshape input vector into row vector
|
||||
|
||||
if min(size(vec))>1
|
||||
horzvec=[];
|
||||
return
|
||||
end
|
||||
|
||||
horzvec=reshape(vec,1,length(vec));
|
||||
3
FittingAndMath/range.m
Normal file
3
FittingAndMath/range.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
function res = range(X)
|
||||
res=max(X(:))-min(X(:));
|
||||
return
|
||||
9
FittingAndMath/vertical.m
Normal file
9
FittingAndMath/vertical.m
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function vertvec=vertical(vec)
|
||||
%reshape input vector into row vector
|
||||
|
||||
if min(size(vec))>1
|
||||
vertvec=[];
|
||||
return
|
||||
end
|
||||
|
||||
vertvec=reshape(vec,length(vec),1);
|
||||
Loading…
Add table
Add a link
Reference in a new issue