Month: June 2024
Approximation of Solution to Poisson-Equation via RBFs but with a change of Basis
Hello! I am currently trying to implement some idea into Matlab but I can’t do it somehow. Probably because my brain is not big enough or because I don’t have that much experience in Matlab… This might be a long text but maybe I will find someone that is interested in this topic aswell and could help me…
First the Theory behind all that:
Lets say we have an open and bounded Domain and we want to solve the Equation
where is known and we have Dirichlet-Boundarycondition
for some known . One approach to do so is to choose
where holds some collocationpoints ( in the Interior and on the Boundary of ) and is an RBF-Kernel, i.e. for some , e.g. is the Gaussian-RBF. The approximand then should meet the conditions
1) ,
2)
wich leads us to solve the linear system of equations
to get the Coefficients where
1) ,
2) ,
3) ,
4) .
Now this one I was already able to implement for the example
with the analytical solution
where I used the inverse Multiquadric
.
This is the corresponding script:
% IMQ-RBF and Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 1;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Generate Evaluation Points
Neval = 100; % Sqrt of Number of Evaluationpoints
a=0;b=4;c=a;d=b; % Bounds for rectangle
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
% Reshape for Plot
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Evaluate Datafunction on rectangle
ueval = u(xeval);
% Generate Collocatoinpoints
N = 25; % Sqrt of number of collocationpoints
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
NI = size(xint,1);
NB = size(xbdy,1);
% Build Evaluationmatrix
DM_int = DistMatr(xeval,xint);
LEM = Lrbf(ep,DM_int);
DM_bdy = DistMatr(xeval,xbdy);
BEM = rbf(ep,DM_bdy);
EM = [LEM BEM];
% Build Collocationmatrix for the system of equations
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB);
BLCM = LBCM’;
DM_BB = DistMatr(xbdy,xbdy);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Datafunction on Collocatoinpoints
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = EM * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
% Plot Approximand and analytical solution
figure(1)
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of solution to Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution of Poisson-Equation’)
function D = DistMatr(A,B)
% Helping function for Evaluating RBFs.
% See if matrices are compatible
A_width = width(A);
B_width = width(B);
if A_width~=B_width
error(‘The matrices are not compatible.’);
end
%Berechnung der Abstandsmatrix
A2 = sum(A.^2,2);
B2 = sum(B.^2,2);
D = sqrt(max(bsxfun(@plus,A2,B2′) – 2*A*B’,0));
end
function [xint,xbdy,x] = GetRectGrid(a,b,c,d,N)
% Generated Grid on choosen rectangle and sorts for interior and boundary
% points.
% Generate Grid
[X1,X2] = meshgrid(linspace(a,b,N),linspace(c,d,N));
x = [X1(:),X2(:)];
% Sort for interior and boundary points
k = 1;l=1; % Counter (There are probably better solutions to this but idc)
xbdy = zeros(4*N-4,2); % Boundary Points
xint = zeros(N^2-(4*N-4),2); % Interior Points
for j = 1:N^2
if x(j,1) == a || x(j,1) == b || x(j,2) == c || x(j,2) == d
xbdy(k,:) = x(j,:);
k = k+1;
else
xint(l,:) = x(j,:);
l = l+1;
end
end
end
Okay so now I want to do basically the same but first I want to do a change of basis. Currently we are working with the Standardbasis that spans some finite dimensional functionspace. The reason to change the basis is that it appears that you gain better evaluation stability if you want to achieve higher accuracy by e.g. choosing very small values for . There’s a lot of theory behind that but lets just lay that by the side for now.
The Idea is to make a simple change of basis to gain some new basis that spans the same space. Therefore we chose
.
Note that we now have instead of for simplicity. We can rewrite this approach to
where is the Coefficientmatrix that holds the Coefficients . Now theres a Theorem that I will not proof here but I will refer to this work by Maryam Pazouki and Robert Schaback in Theorem 3.1 and Theorem 6.1 but the Theorem basically says that every possible basis we can get by this is uniquley characterizable by a factorization of the Matrix
into some Matrix and the inverse of the Coefficientmatrix , i.e.. . For example if we take the Cholesky-Decomposition of we end up with as the coefficientmatrix wich leads us to the so called Newton-Basis , described here in chapter 3.7. Since the RBF-Kernel is because we take the double Laplacian of it, the Newtonbasisfunktions are too since they are just linear combinations of the Kernel and the laplacian is a linear differential operator. Therefore
and .
In summary I want do the approximation of the solution of the Poisson-Equation but not use the standard rbf basis but do a change of basis into the newton basis and then chose the approach
for the approximand to solve the linear system of equations that I describe above but now it has Submatrices and . Obviously after that I’d like to Plot the resulting approximand to see how it looks. I already tried it, but it didnt work like that… I just have alot of trouble to implement that… Here is my Approach:
% Inverse Multiquadric RBF and its Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 2;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and its Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Evaluationpoints
Neval = 100;
a=0;b=4;c=a;d=b;
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Collocationpoints
N = 20;
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
x=[xint;xbdy]; % Sorting x… hmm…
NI = size(xint,1);
NB = size(xbdy,1);
% Evaluate Datafunction on Collocationpoints …
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% .. and on the Evaluationpoints
ueval = u(xeval);
% Evaluate needed Kernel-Matrices
% % % This part works fine. B is looking good.
A1 = rbf(ep,DistMatr(x,x));
A2 = rbf(ep,DistMatr(xeval,x));
% Cholesky decomposition
L = chol(A1,’lower’);
% Each column is one newtonbasisfunction evaluated on the evaluationpoints
newton = A2/L’;
% This is the Coefficent Matrix
B = inv(L)’;
% Collocationmatrix
% % % This is probably not the way to do it… I dont know how to use B…
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II)*B(1:NI,1:NI);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB).*B(1:NI,NI+1:end);
DM_BI = DistMatr(xbdy,xint);
BLCM = Lrbf(ep,DM_BI).*B(NI+1:end,1:NI);
DM_BB = DistMatr(xbdy,xbdy)*B(NI+1:end,NI+1:end);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = newton * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
figure(1) % Here you can see how its just not working how I want it to.
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of the solution to the Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution to the Poisson-Equation’)
I hope someone of you could help me manage this problem. Thank you very much! Kind regards, Max.Hello! I am currently trying to implement some idea into Matlab but I can’t do it somehow. Probably because my brain is not big enough or because I don’t have that much experience in Matlab… This might be a long text but maybe I will find someone that is interested in this topic aswell and could help me…
First the Theory behind all that:
Lets say we have an open and bounded Domain and we want to solve the Equation
where is known and we have Dirichlet-Boundarycondition
for some known . One approach to do so is to choose
where holds some collocationpoints ( in the Interior and on the Boundary of ) and is an RBF-Kernel, i.e. for some , e.g. is the Gaussian-RBF. The approximand then should meet the conditions
1) ,
2)
wich leads us to solve the linear system of equations
to get the Coefficients where
1) ,
2) ,
3) ,
4) .
Now this one I was already able to implement for the example
with the analytical solution
where I used the inverse Multiquadric
.
This is the corresponding script:
% IMQ-RBF and Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 1;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Generate Evaluation Points
Neval = 100; % Sqrt of Number of Evaluationpoints
a=0;b=4;c=a;d=b; % Bounds for rectangle
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
% Reshape for Plot
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Evaluate Datafunction on rectangle
ueval = u(xeval);
% Generate Collocatoinpoints
N = 25; % Sqrt of number of collocationpoints
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
NI = size(xint,1);
NB = size(xbdy,1);
% Build Evaluationmatrix
DM_int = DistMatr(xeval,xint);
LEM = Lrbf(ep,DM_int);
DM_bdy = DistMatr(xeval,xbdy);
BEM = rbf(ep,DM_bdy);
EM = [LEM BEM];
% Build Collocationmatrix for the system of equations
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB);
BLCM = LBCM’;
DM_BB = DistMatr(xbdy,xbdy);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Datafunction on Collocatoinpoints
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = EM * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
% Plot Approximand and analytical solution
figure(1)
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of solution to Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution of Poisson-Equation’)
function D = DistMatr(A,B)
% Helping function for Evaluating RBFs.
% See if matrices are compatible
A_width = width(A);
B_width = width(B);
if A_width~=B_width
error(‘The matrices are not compatible.’);
end
%Berechnung der Abstandsmatrix
A2 = sum(A.^2,2);
B2 = sum(B.^2,2);
D = sqrt(max(bsxfun(@plus,A2,B2′) – 2*A*B’,0));
end
function [xint,xbdy,x] = GetRectGrid(a,b,c,d,N)
% Generated Grid on choosen rectangle and sorts for interior and boundary
% points.
% Generate Grid
[X1,X2] = meshgrid(linspace(a,b,N),linspace(c,d,N));
x = [X1(:),X2(:)];
% Sort for interior and boundary points
k = 1;l=1; % Counter (There are probably better solutions to this but idc)
xbdy = zeros(4*N-4,2); % Boundary Points
xint = zeros(N^2-(4*N-4),2); % Interior Points
for j = 1:N^2
if x(j,1) == a || x(j,1) == b || x(j,2) == c || x(j,2) == d
xbdy(k,:) = x(j,:);
k = k+1;
else
xint(l,:) = x(j,:);
l = l+1;
end
end
end
Okay so now I want to do basically the same but first I want to do a change of basis. Currently we are working with the Standardbasis that spans some finite dimensional functionspace. The reason to change the basis is that it appears that you gain better evaluation stability if you want to achieve higher accuracy by e.g. choosing very small values for . There’s a lot of theory behind that but lets just lay that by the side for now.
The Idea is to make a simple change of basis to gain some new basis that spans the same space. Therefore we chose
.
Note that we now have instead of for simplicity. We can rewrite this approach to
where is the Coefficientmatrix that holds the Coefficients . Now theres a Theorem that I will not proof here but I will refer to this work by Maryam Pazouki and Robert Schaback in Theorem 3.1 and Theorem 6.1 but the Theorem basically says that every possible basis we can get by this is uniquley characterizable by a factorization of the Matrix
into some Matrix and the inverse of the Coefficientmatrix , i.e.. . For example if we take the Cholesky-Decomposition of we end up with as the coefficientmatrix wich leads us to the so called Newton-Basis , described here in chapter 3.7. Since the RBF-Kernel is because we take the double Laplacian of it, the Newtonbasisfunktions are too since they are just linear combinations of the Kernel and the laplacian is a linear differential operator. Therefore
and .
In summary I want do the approximation of the solution of the Poisson-Equation but not use the standard rbf basis but do a change of basis into the newton basis and then chose the approach
for the approximand to solve the linear system of equations that I describe above but now it has Submatrices and . Obviously after that I’d like to Plot the resulting approximand to see how it looks. I already tried it, but it didnt work like that… I just have alot of trouble to implement that… Here is my Approach:
% Inverse Multiquadric RBF and its Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 2;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and its Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Evaluationpoints
Neval = 100;
a=0;b=4;c=a;d=b;
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Collocationpoints
N = 20;
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
x=[xint;xbdy]; % Sorting x… hmm…
NI = size(xint,1);
NB = size(xbdy,1);
% Evaluate Datafunction on Collocationpoints …
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% .. and on the Evaluationpoints
ueval = u(xeval);
% Evaluate needed Kernel-Matrices
% % % This part works fine. B is looking good.
A1 = rbf(ep,DistMatr(x,x));
A2 = rbf(ep,DistMatr(xeval,x));
% Cholesky decomposition
L = chol(A1,’lower’);
% Each column is one newtonbasisfunction evaluated on the evaluationpoints
newton = A2/L’;
% This is the Coefficent Matrix
B = inv(L)’;
% Collocationmatrix
% % % This is probably not the way to do it… I dont know how to use B…
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II)*B(1:NI,1:NI);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB).*B(1:NI,NI+1:end);
DM_BI = DistMatr(xbdy,xint);
BLCM = Lrbf(ep,DM_BI).*B(NI+1:end,1:NI);
DM_BB = DistMatr(xbdy,xbdy)*B(NI+1:end,NI+1:end);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = newton * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
figure(1) % Here you can see how its just not working how I want it to.
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of the solution to the Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution to the Poisson-Equation’)
I hope someone of you could help me manage this problem. Thank you very much! Kind regards, Max. Hello! I am currently trying to implement some idea into Matlab but I can’t do it somehow. Probably because my brain is not big enough or because I don’t have that much experience in Matlab… This might be a long text but maybe I will find someone that is interested in this topic aswell and could help me…
First the Theory behind all that:
Lets say we have an open and bounded Domain and we want to solve the Equation
where is known and we have Dirichlet-Boundarycondition
for some known . One approach to do so is to choose
where holds some collocationpoints ( in the Interior and on the Boundary of ) and is an RBF-Kernel, i.e. for some , e.g. is the Gaussian-RBF. The approximand then should meet the conditions
1) ,
2)
wich leads us to solve the linear system of equations
to get the Coefficients where
1) ,
2) ,
3) ,
4) .
Now this one I was already able to implement for the example
with the analytical solution
where I used the inverse Multiquadric
.
This is the corresponding script:
% IMQ-RBF and Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 1;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Generate Evaluation Points
Neval = 100; % Sqrt of Number of Evaluationpoints
a=0;b=4;c=a;d=b; % Bounds for rectangle
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
% Reshape for Plot
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Evaluate Datafunction on rectangle
ueval = u(xeval);
% Generate Collocatoinpoints
N = 25; % Sqrt of number of collocationpoints
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
NI = size(xint,1);
NB = size(xbdy,1);
% Build Evaluationmatrix
DM_int = DistMatr(xeval,xint);
LEM = Lrbf(ep,DM_int);
DM_bdy = DistMatr(xeval,xbdy);
BEM = rbf(ep,DM_bdy);
EM = [LEM BEM];
% Build Collocationmatrix for the system of equations
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB);
BLCM = LBCM’;
DM_BB = DistMatr(xbdy,xbdy);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Datafunction on Collocatoinpoints
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = EM * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
% Plot Approximand and analytical solution
figure(1)
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of solution to Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution of Poisson-Equation’)
function D = DistMatr(A,B)
% Helping function for Evaluating RBFs.
% See if matrices are compatible
A_width = width(A);
B_width = width(B);
if A_width~=B_width
error(‘The matrices are not compatible.’);
end
%Berechnung der Abstandsmatrix
A2 = sum(A.^2,2);
B2 = sum(B.^2,2);
D = sqrt(max(bsxfun(@plus,A2,B2′) – 2*A*B’,0));
end
function [xint,xbdy,x] = GetRectGrid(a,b,c,d,N)
% Generated Grid on choosen rectangle and sorts for interior and boundary
% points.
% Generate Grid
[X1,X2] = meshgrid(linspace(a,b,N),linspace(c,d,N));
x = [X1(:),X2(:)];
% Sort for interior and boundary points
k = 1;l=1; % Counter (There are probably better solutions to this but idc)
xbdy = zeros(4*N-4,2); % Boundary Points
xint = zeros(N^2-(4*N-4),2); % Interior Points
for j = 1:N^2
if x(j,1) == a || x(j,1) == b || x(j,2) == c || x(j,2) == d
xbdy(k,:) = x(j,:);
k = k+1;
else
xint(l,:) = x(j,:);
l = l+1;
end
end
end
Okay so now I want to do basically the same but first I want to do a change of basis. Currently we are working with the Standardbasis that spans some finite dimensional functionspace. The reason to change the basis is that it appears that you gain better evaluation stability if you want to achieve higher accuracy by e.g. choosing very small values for . There’s a lot of theory behind that but lets just lay that by the side for now.
The Idea is to make a simple change of basis to gain some new basis that spans the same space. Therefore we chose
.
Note that we now have instead of for simplicity. We can rewrite this approach to
where is the Coefficientmatrix that holds the Coefficients . Now theres a Theorem that I will not proof here but I will refer to this work by Maryam Pazouki and Robert Schaback in Theorem 3.1 and Theorem 6.1 but the Theorem basically says that every possible basis we can get by this is uniquley characterizable by a factorization of the Matrix
into some Matrix and the inverse of the Coefficientmatrix , i.e.. . For example if we take the Cholesky-Decomposition of we end up with as the coefficientmatrix wich leads us to the so called Newton-Basis , described here in chapter 3.7. Since the RBF-Kernel is because we take the double Laplacian of it, the Newtonbasisfunktions are too since they are just linear combinations of the Kernel and the laplacian is a linear differential operator. Therefore
and .
In summary I want do the approximation of the solution of the Poisson-Equation but not use the standard rbf basis but do a change of basis into the newton basis and then chose the approach
for the approximand to solve the linear system of equations that I describe above but now it has Submatrices and . Obviously after that I’d like to Plot the resulting approximand to see how it looks. I already tried it, but it didnt work like that… I just have alot of trouble to implement that… Here is my Approach:
% Inverse Multiquadric RBF and its Laplacians
rbf = @(e,r) 1./sqrt(1+(e*r).^2); ep = 2;
Lrbf = @(e,r) e^2*((e*r).^2-2)./(1+(e*r).^2).^(5/2);
L2rbf = @(e,r) 3*e^4*(3*(e*r).^4-24*(e*r).^2+8)./(1+(e*r).^2).^(9/2);
% Datafunction and its Laplacian
u = @(x) sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
Lu = @(x) -1.25*pi^2*sin(pi*x(:,1)).*cos(pi*x(:,2)/2);
% Evaluationpoints
Neval = 100;
a=0;b=4;c=a;d=b;
[~,~,xeval]=GetRectGrid(a,b,c,d,Neval);
X = reshape(xeval(:,1),Neval,Neval);
Y = reshape(xeval(:,2),Neval,Neval);
% Collocationpoints
N = 20;
[xint,xbdy,x]=GetRectGrid(a,b,c,d,N);
x=[xint;xbdy]; % Sorting x… hmm…
NI = size(xint,1);
NB = size(xbdy,1);
% Evaluate Datafunction on Collocationpoints …
ux = zeros(N^2,1);
ux(1:NI) = Lu(xint);
% Boundary Conditions
indx = find(xbdy(:,2)==0 | xbdy(:,2)==4);
ux(NI+indx) = sin(pi*xbdy(indx,1));
% .. and on the Evaluationpoints
ueval = u(xeval);
% Evaluate needed Kernel-Matrices
% % % This part works fine. B is looking good.
A1 = rbf(ep,DistMatr(x,x));
A2 = rbf(ep,DistMatr(xeval,x));
% Cholesky decomposition
L = chol(A1,’lower’);
% Each column is one newtonbasisfunction evaluated on the evaluationpoints
newton = A2/L’;
% This is the Coefficent Matrix
B = inv(L)’;
% Collocationmatrix
% % % This is probably not the way to do it… I dont know how to use B…
DM_II = DistMatr(xint,xint);
LLCM = L2rbf(ep,DM_II)*B(1:NI,1:NI);
DM_IB = DistMatr(xint,xbdy);
LBCM = Lrbf(ep,DM_IB).*B(1:NI,NI+1:end);
DM_BI = DistMatr(xbdy,xint);
BLCM = Lrbf(ep,DM_BI).*B(NI+1:end,1:NI);
DM_BB = DistMatr(xbdy,xbdy)*B(NI+1:end,NI+1:end);
BBCM = rbf(ep,DM_BB);
CM = [LLCM LBCM; BLCM BBCM];
% Evaluate Approximand
warning(‘off’,’MATLAB:nearlySingularMatrix’)
approx = newton * (CMux);
warning(‘on’,’MATLAB:nearlySingularMatrix’)
figure(1) % Here you can see how its just not working how I want it to.
approx2 = reshape(approx,Neval,Neval);
surf(X,Y,approx2,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title([‘Approximation of the solution to the Poisson-Equation for N=’,num2str(N^2)])
figure(2);
ueval2 = reshape(ueval,Neval,Neval);
surf(X,Y,ueval2,’FaceAlpha’,0.5,’EdgeColor’,’interp’)
colormap cool; camlight; lighting gouraud; material dull;
title(‘Solution to the Poisson-Equation’)
I hope someone of you could help me manage this problem. Thank you very much! Kind regards, Max. rbf, radial basis function, interpolation, differential equations, kernel, approximation MATLAB Answers — New Questions
Accessing Fit Coefficients from Curve Fitting
Hello, I am attempting to generate a graph of the full width half max (FWHM) of multiple sets of data but want to first fit each dataset to a Gaussian. Currently, I am calculating the FWHM by indexing the first and last instances of the half-max value for each dataset, then graphing all of these values. This works alright; however, I would like to improve upon this by fitting each dataset to a Gaussian distribution and then use the calculated Gaussian coefficients from the fitting in order to find the FWHM, as this would be more accurate. I have been able to fit each dataset to a Gaussian using the fit() function. However, I have run into an issue where I seem to be unable to access the generated Gaussian coefficients, which are what I need in order to be able to recalculate the FWHM. Does anyone know how I might be able to access these coefficients or generate them in such a way that I would be able to access them? Below I have copied the portion of my code where I am fitting the data along with a screenshot of the particular math I am referring to using the Gaussian coefficients to calculate the FWHM. Thank you so much!
y_fit = data.’; % turns data into a variable for fit, transposes to column
l_y = length(y_fit); % generates a variable with the length of y_fit
x_fit = linspace(0,l_y,l_y).’; % creates a column variable simply for the x-axis
data_fit = fit(x_fit,y_fit,’gauss1′); % this creates a fitted data setHello, I am attempting to generate a graph of the full width half max (FWHM) of multiple sets of data but want to first fit each dataset to a Gaussian. Currently, I am calculating the FWHM by indexing the first and last instances of the half-max value for each dataset, then graphing all of these values. This works alright; however, I would like to improve upon this by fitting each dataset to a Gaussian distribution and then use the calculated Gaussian coefficients from the fitting in order to find the FWHM, as this would be more accurate. I have been able to fit each dataset to a Gaussian using the fit() function. However, I have run into an issue where I seem to be unable to access the generated Gaussian coefficients, which are what I need in order to be able to recalculate the FWHM. Does anyone know how I might be able to access these coefficients or generate them in such a way that I would be able to access them? Below I have copied the portion of my code where I am fitting the data along with a screenshot of the particular math I am referring to using the Gaussian coefficients to calculate the FWHM. Thank you so much!
y_fit = data.’; % turns data into a variable for fit, transposes to column
l_y = length(y_fit); % generates a variable with the length of y_fit
x_fit = linspace(0,l_y,l_y).’; % creates a column variable simply for the x-axis
data_fit = fit(x_fit,y_fit,’gauss1′); % this creates a fitted data set Hello, I am attempting to generate a graph of the full width half max (FWHM) of multiple sets of data but want to first fit each dataset to a Gaussian. Currently, I am calculating the FWHM by indexing the first and last instances of the half-max value for each dataset, then graphing all of these values. This works alright; however, I would like to improve upon this by fitting each dataset to a Gaussian distribution and then use the calculated Gaussian coefficients from the fitting in order to find the FWHM, as this would be more accurate. I have been able to fit each dataset to a Gaussian using the fit() function. However, I have run into an issue where I seem to be unable to access the generated Gaussian coefficients, which are what I need in order to be able to recalculate the FWHM. Does anyone know how I might be able to access these coefficients or generate them in such a way that I would be able to access them? Below I have copied the portion of my code where I am fitting the data along with a screenshot of the particular math I am referring to using the Gaussian coefficients to calculate the FWHM. Thank you so much!
y_fit = data.’; % turns data into a variable for fit, transposes to column
l_y = length(y_fit); % generates a variable with the length of y_fit
x_fit = linspace(0,l_y,l_y).’; % creates a column variable simply for the x-axis
data_fit = fit(x_fit,y_fit,’gauss1′); % this creates a fitted data set curve fitting, gaussian distribution MATLAB Answers — New Questions
New Here!! Glad to be here!
Hello Everyone.
I just joined the techcommunity. I am glad to be a part of this community.
Hello Everyone. I just joined the techcommunity. I am glad to be a part of this community. Read More
i need code to generate key using PSO then adding the key to image
i need code to generate key using PSO then adding the key to image.i need code to generate key using PSO then adding the key to image. i need code to generate key using PSO then adding the key to image. image, image processing MATLAB Answers — New Questions
csv to fft matlab
Hello everybody,
I’m trying to convert two csv files to fft and I looked on different forums and tried a few solutions but nothing conclusive.
Someone could help me please.
ThanksHello everybody,
I’m trying to convert two csv files to fft and I looked on different forums and tried a few solutions but nothing conclusive.
Someone could help me please.
Thanks Hello everybody,
I’m trying to convert two csv files to fft and I looked on different forums and tried a few solutions but nothing conclusive.
Someone could help me please.
Thanks fft, csv MATLAB Answers — New Questions
eval function in for-loop and change of numbers bigger through NaN
I have 108 variables with same name but with consecutive numbering. Each of this variables I want to check if there is a value bigger 1000. When yes, then it will be exchanged through NaN.
I try to solve with eval and for-loop, but it doesn’t work.
I know the function which changes a value bigger 1000 through NaN.
Function: Temperatur_1(Temperatur_1>1000)=NaN;
Dynamics variabels are: Temperatur_1, Temperatur_2, etc.
eval-function: eval(strcat(‘Temperatur_’,num2str(e)))
for i=1:108
tbd
end
What is the function for checking each variable for > 1000 and saving it in the same variable?
Thank you in advance for your support and solution.I have 108 variables with same name but with consecutive numbering. Each of this variables I want to check if there is a value bigger 1000. When yes, then it will be exchanged through NaN.
I try to solve with eval and for-loop, but it doesn’t work.
I know the function which changes a value bigger 1000 through NaN.
Function: Temperatur_1(Temperatur_1>1000)=NaN;
Dynamics variabels are: Temperatur_1, Temperatur_2, etc.
eval-function: eval(strcat(‘Temperatur_’,num2str(e)))
for i=1:108
tbd
end
What is the function for checking each variable for > 1000 and saving it in the same variable?
Thank you in advance for your support and solution. I have 108 variables with same name but with consecutive numbering. Each of this variables I want to check if there is a value bigger 1000. When yes, then it will be exchanged through NaN.
I try to solve with eval and for-loop, but it doesn’t work.
I know the function which changes a value bigger 1000 through NaN.
Function: Temperatur_1(Temperatur_1>1000)=NaN;
Dynamics variabels are: Temperatur_1, Temperatur_2, etc.
eval-function: eval(strcat(‘Temperatur_’,num2str(e)))
for i=1:108
tbd
end
What is the function for checking each variable for > 1000 and saving it in the same variable?
Thank you in advance for your support and solution. eval, dynamic variable MATLAB Answers — New Questions
How to use FFT in matlab using imported data in time domain excel file
I have used a multimeter to measure my phototransistor
and I got one excel file with time versus Magnitude.
But I got some noise, so I want to use Matlab to do FFT
from time domain to frequency domain(frequency versus magnitude) called Photorespone.
I attach my file as below.
I wanna make this kind of figure, freq versus amplitude.
<</matlabcentral/answers/uploaded_files/71667/17160838_1646141328735588_1887025192_n.png>>I have used a multimeter to measure my phototransistor
and I got one excel file with time versus Magnitude.
But I got some noise, so I want to use Matlab to do FFT
from time domain to frequency domain(frequency versus magnitude) called Photorespone.
I attach my file as below.
I wanna make this kind of figure, freq versus amplitude.
<</matlabcentral/answers/uploaded_files/71667/17160838_1646141328735588_1887025192_n.png>> I have used a multimeter to measure my phototransistor
and I got one excel file with time versus Magnitude.
But I got some noise, so I want to use Matlab to do FFT
from time domain to frequency domain(frequency versus magnitude) called Photorespone.
I attach my file as below.
I wanna make this kind of figure, freq versus amplitude.
<</matlabcentral/answers/uploaded_files/71667/17160838_1646141328735588_1887025192_n.png>> fft MATLAB Answers — New Questions
switch counts for each item
Dear Experts,
I have a Data (as attached ),
In column “D”, we have item name as “rnti” and each rnti can have switch in ueBwpId (from 0>1>2),
in sheet2, I want to make a summary for each rnti how many switches happened example as below
for rnti = [28559] in column “E”, should have count of all the switches from ueBwpId from 2->1 ,
Thanks in Advance,
Br,
Anupam
Dear Experts, I have a Data (as attached ),In column “D”, we have item name as “rnti” and each rnti can have switch in ueBwpId (from 0>1>2),in sheet2, I want to make a summary for each rnti how many switches happened example as belowfor rnti = [28559] in column “E”, should have count of all the switches from ueBwpId from 2->1 ,Thanks in Advance,Br,Anupam Read More
chanvannak2211.powerappsportals.com
chanvannak2211.powerappsportals.com
chanvannak2211.powerappsportals.com
chanvannak2211.powerappsportals.com chanvannak2211.powerappsportals.com Read More
Help with weekly data project
Hi! I work with attendance data every week and don’t know much about Excel or how I can make things quicker and easier. I work with attendance data, which comes from our ticketing service in three columns – amount of tickets registered in each order, visitor zip code for those tickets, and the day of the week the tickets were for (see example below). Basically, I need the zip codes to each appear in a separate column the amount of times that a ticket is made with that zip code (so if there are 9 total tickets for the zip code 19107, the new column would have nine cells reading 19107). These new columns would represent the day of the week the ticket occurred (see second image below) From this point, I have shortcuts that make the data easy to work with for the purposes of my reporting, so no recommendations are needed for how to take the data forward from there. I just don’t want to have to individually type zip codes for the amount of times they occur. Please let me know what I can do or if further explanation is needed.
Hi! I work with attendance data every week and don’t know much about Excel or how I can make things quicker and easier. I work with attendance data, which comes from our ticketing service in three columns – amount of tickets registered in each order, visitor zip code for those tickets, and the day of the week the tickets were for (see example below). Basically, I need the zip codes to each appear in a separate column the amount of times that a ticket is made with that zip code (so if there are 9 total tickets for the zip code 19107, the new column would have nine cells reading 19107). These new columns would represent the day of the week the ticket occurred (see second image below) From this point, I have shortcuts that make the data easy to work with for the purposes of my reporting, so no recommendations are needed for how to take the data forward from there. I just don’t want to have to individually type zip codes for the amount of times they occur. Please let me know what I can do or if further explanation is needed. Read More
Even & Odd Discrete time Signals
I am writing a program to seperate, plot even and odd parts of a discrete time signal. Following is my code:
I am getting error at line 3 & 4. "Array indices must be positive integers or logical values."
Since I am trying to flip and invert the signal x[n] , so ‘x(-n)’ is obvious to use but I am getting error. Kindly help.
n= -3:4;
x=[0 0 0 2 3 -1 2 -3];
xe= ( x(n)+x(-n) )/2;
xo= ( x(n)-x(-n) )/2;
subplot(311);stem(n,x);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Original Signal’);
subplot(312);stem(n,xe);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Even Signal’);
subplot(313);stem(n,xo);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Odd Signal’);I am writing a program to seperate, plot even and odd parts of a discrete time signal. Following is my code:
I am getting error at line 3 & 4. "Array indices must be positive integers or logical values."
Since I am trying to flip and invert the signal x[n] , so ‘x(-n)’ is obvious to use but I am getting error. Kindly help.
n= -3:4;
x=[0 0 0 2 3 -1 2 -3];
xe= ( x(n)+x(-n) )/2;
xo= ( x(n)-x(-n) )/2;
subplot(311);stem(n,x);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Original Signal’);
subplot(312);stem(n,xe);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Even Signal’);
subplot(313);stem(n,xo);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Odd Signal’); I am writing a program to seperate, plot even and odd parts of a discrete time signal. Following is my code:
I am getting error at line 3 & 4. "Array indices must be positive integers or logical values."
Since I am trying to flip and invert the signal x[n] , so ‘x(-n)’ is obvious to use but I am getting error. Kindly help.
n= -3:4;
x=[0 0 0 2 3 -1 2 -3];
xe= ( x(n)+x(-n) )/2;
xo= ( x(n)-x(-n) )/2;
subplot(311);stem(n,x);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Original Signal’);
subplot(312);stem(n,xe);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Even Signal’);
subplot(313);stem(n,xo);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Odd Signal’); dicrete_time_signal MATLAB Answers — New Questions
Proving one function is greater than other?
I want to see where is this inequality true
[
frac{log(log(x))}{21.233 log(x)} > frac{1}{53.989 (log(x)^{2/3})(log(log(x))^{1/3})}
]
where x in (e^e,∞).I want to see where is this inequality true
[
frac{log(log(x))}{21.233 log(x)} > frac{1}{53.989 (log(x)^{2/3})(log(log(x))^{1/3})}
]
where x in (e^e,∞). I want to see where is this inequality true
[
frac{log(log(x))}{21.233 log(x)} > frac{1}{53.989 (log(x)^{2/3})(log(log(x))^{1/3})}
]
where x in (e^e,∞). staff MATLAB Answers — New Questions
Network Printer Issue
# Shared printer disconnects every time the user restarts the computer. I have Several Work-group computers installed windows 10 pro. i fed up with this issue, so how could i solve this please.!?
# Shared printer disconnects every time the user restarts the computer. I have Several Work-group computers installed windows 10 pro. i fed up with this issue, so how could i solve this please.!? Read More
Windows One Drive shared folder suddenly become shortcut instead of folders
Hi,
I am having an issue that I need help with. I have my One Drive account for several years. I have my main account signed in on my laptop. I have 4 other users sharing their folder with edit access to my main account. I add them as short cut to my main account. In the past, on my laptop, they function as folders. Meaning, I can move, delete, add files and they essentially function as a folder. Now, all my shared folder from my other users suddenly becomes short cut. When I open the folder, it brings me to the browser for me to sign in and view them. This never happened before and I am not sure what caused it. Please help.
Hi, I am having an issue that I need help with. I have my One Drive account for several years. I have my main account signed in on my laptop. I have 4 other users sharing their folder with edit access to my main account. I add them as short cut to my main account. In the past, on my laptop, they function as folders. Meaning, I can move, delete, add files and they essentially function as a folder. Now, all my shared folder from my other users suddenly becomes short cut. When I open the folder, it brings me to the browser for me to sign in and view them. This never happened before and I am not sure what caused it. Please help. Read More
How to remove fluctuations caused by transfer function?
As most of the sensor have some or other kind of time delay, in my model I have used a temperature sensor the signal provided by the sensor is going through a transfer function just to replicate its true nature (i.e thermal inertia). As the sensor data is being used in a feed back loop. The senor with a transfer function is causing eratic behaviour of my whole model. Because when the setpoint is high enough the sensor reading are all over the place. What should I do?As most of the sensor have some or other kind of time delay, in my model I have used a temperature sensor the signal provided by the sensor is going through a transfer function just to replicate its true nature (i.e thermal inertia). As the sensor data is being used in a feed back loop. The senor with a transfer function is causing eratic behaviour of my whole model. Because when the setpoint is high enough the sensor reading are all over the place. What should I do? As most of the sensor have some or other kind of time delay, in my model I have used a temperature sensor the signal provided by the sensor is going through a transfer function just to replicate its true nature (i.e thermal inertia). As the sensor data is being used in a feed back loop. The senor with a transfer function is causing eratic behaviour of my whole model. Because when the setpoint is high enough the sensor reading are all over the place. What should I do? transfer function, steady state error MATLAB Answers — New Questions
GARCH(1,1): Matrix from standardized residuals do not have exact 1’s on the diagonal
Hello,
I am trying to estimate a GARCH(1,1), get the standardized residuals and form a matrix from them. My R_bar does not have exact 1’s on the diagonal even though they are very close to 1 (for example, 0.9983, 0.9997, 1.023…). Specifically I trying to do this:
data = parquetread(‘/datacommons/dfe/cov/close_to_close_2010-2014.parquet’);
returns = data{:, 2:end};
numAssets = size(returns, 2);
%returns look like this:
%header stock_1 stock_2 …
%date1 return_1 of stock 1 return_1 of stock 2
%date2 return_2 of stock 1 return_2 of stock 2
%…
%returns are not demeaned
mdl = cell(numAssets, 1);
estMdl = cell(numAssets, 1);
condVar = cell(numAssets, 1);
standardizedResiduals = cell(numAssets, 1);
residuals = cell(numAssets, 1);
for i = 1:numAssets
mdl{i} = garch(‘Offset’, NaN, ‘GARCHLags’, 1, ‘ARCHLags’, 1); %I did not demean the returns so I let the model estimate the "offset" parameter
estMdl{i} = estimate(mdl{i}, returns(:, i), ‘Display’, ‘off’);
condVar{i} = infer(estMdl{i}, returns(:, i));
residuals{i} = (returns(:, i) – estMdl{i}.Offset) ;
standardizedResiduals{i} = (returns(:, i) – estMdl{i}.Offset) ./ sqrt(condVar{i}); %Step4 from: https://www.mathworks.com/help/econ/infer-conditional-variances.html
end
% concat into a matrix of TxN where T is the number of time periods and N
% is the number of stocks
standardizedResidualsMat = zeros(T, numAssets);
for i = 1:numAssets
standardizedResidualsMat(:, i) = standardizedResiduals{i};
end
R_bar = zeros(numAssets, numAssets);
for t = 1:T
R_bar = R_bar + (standardizedResidualsMat(t, :)’ * standardizedResidualsMat(t, :));
end
R_bar = R_bar / T;Hello,
I am trying to estimate a GARCH(1,1), get the standardized residuals and form a matrix from them. My R_bar does not have exact 1’s on the diagonal even though they are very close to 1 (for example, 0.9983, 0.9997, 1.023…). Specifically I trying to do this:
data = parquetread(‘/datacommons/dfe/cov/close_to_close_2010-2014.parquet’);
returns = data{:, 2:end};
numAssets = size(returns, 2);
%returns look like this:
%header stock_1 stock_2 …
%date1 return_1 of stock 1 return_1 of stock 2
%date2 return_2 of stock 1 return_2 of stock 2
%…
%returns are not demeaned
mdl = cell(numAssets, 1);
estMdl = cell(numAssets, 1);
condVar = cell(numAssets, 1);
standardizedResiduals = cell(numAssets, 1);
residuals = cell(numAssets, 1);
for i = 1:numAssets
mdl{i} = garch(‘Offset’, NaN, ‘GARCHLags’, 1, ‘ARCHLags’, 1); %I did not demean the returns so I let the model estimate the "offset" parameter
estMdl{i} = estimate(mdl{i}, returns(:, i), ‘Display’, ‘off’);
condVar{i} = infer(estMdl{i}, returns(:, i));
residuals{i} = (returns(:, i) – estMdl{i}.Offset) ;
standardizedResiduals{i} = (returns(:, i) – estMdl{i}.Offset) ./ sqrt(condVar{i}); %Step4 from: https://www.mathworks.com/help/econ/infer-conditional-variances.html
end
% concat into a matrix of TxN where T is the number of time periods and N
% is the number of stocks
standardizedResidualsMat = zeros(T, numAssets);
for i = 1:numAssets
standardizedResidualsMat(:, i) = standardizedResiduals{i};
end
R_bar = zeros(numAssets, numAssets);
for t = 1:T
R_bar = R_bar + (standardizedResidualsMat(t, :)’ * standardizedResidualsMat(t, :));
end
R_bar = R_bar / T; Hello,
I am trying to estimate a GARCH(1,1), get the standardized residuals and form a matrix from them. My R_bar does not have exact 1’s on the diagonal even though they are very close to 1 (for example, 0.9983, 0.9997, 1.023…). Specifically I trying to do this:
data = parquetread(‘/datacommons/dfe/cov/close_to_close_2010-2014.parquet’);
returns = data{:, 2:end};
numAssets = size(returns, 2);
%returns look like this:
%header stock_1 stock_2 …
%date1 return_1 of stock 1 return_1 of stock 2
%date2 return_2 of stock 1 return_2 of stock 2
%…
%returns are not demeaned
mdl = cell(numAssets, 1);
estMdl = cell(numAssets, 1);
condVar = cell(numAssets, 1);
standardizedResiduals = cell(numAssets, 1);
residuals = cell(numAssets, 1);
for i = 1:numAssets
mdl{i} = garch(‘Offset’, NaN, ‘GARCHLags’, 1, ‘ARCHLags’, 1); %I did not demean the returns so I let the model estimate the "offset" parameter
estMdl{i} = estimate(mdl{i}, returns(:, i), ‘Display’, ‘off’);
condVar{i} = infer(estMdl{i}, returns(:, i));
residuals{i} = (returns(:, i) – estMdl{i}.Offset) ;
standardizedResiduals{i} = (returns(:, i) – estMdl{i}.Offset) ./ sqrt(condVar{i}); %Step4 from: https://www.mathworks.com/help/econ/infer-conditional-variances.html
end
% concat into a matrix of TxN where T is the number of time periods and N
% is the number of stocks
standardizedResidualsMat = zeros(T, numAssets);
for i = 1:numAssets
standardizedResidualsMat(:, i) = standardizedResiduals{i};
end
R_bar = zeros(numAssets, numAssets);
for t = 1:T
R_bar = R_bar + (standardizedResidualsMat(t, :)’ * standardizedResidualsMat(t, :));
end
R_bar = R_bar / T; garch, econometrics toolbox MATLAB Answers — New Questions
SENSITIVITY ANALYSIS OF A SYSTEM OF AN ODE USING NORMALIZED SENSITIVITY FUNCTION
I want to perform the sensitivity analysis on the parameters of an ODE SIR model using normalized sensitivity function. I used the following code below. When it was run, I got this error: "undefined functionnor variable ‘p’, error in epidemic1 line8, F=ode45(@epidemic,ic,p)". How can I resolve it to get the plots?
My interest is to get the figure (3) i.e. The plot of nomalized sensitivity functions against time
function epidemic1()
clc
beta=0.4; gamma=0.04;
p1 = [beta gamma];
ic = [995;5;0];
F = ode45(@epidemic,ic,p);
sol1 = solve(F,0,80)
figure(1)
plot(sol1.Time,sol1.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’$beta=0.4$, $gamma=0.04$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
Figure(2)
p2 = [0.2 0.1];
F.Parameters = p2;
F.Sensitivity = odeSensitivity;
sol2 = solve(F,0,80)
plot(sol2.Time,sol2.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
U11 = squeeze(sol2.Sensitivity(1,1,:))’.*(p2(1)./sol2.Solution(1,:));
U12 = squeeze(sol2.Sensitivity(1,2,:))’.*(p2(2)./sol2.Solution(1,:));
U21 = squeeze(sol2.Sensitivity(2,1,:))’.*(p2(1)./sol2.Solution(2,:));
U22 = squeeze(sol2.Sensitivity(2,2,:))’.*(p2(2)./sol2.Solution(2,:));
U31 = squeeze(sol2.Sensitivity(3,1,:))’.*(p2(1)./sol2.Solution(3,:));
U32 = squeeze(sol2.Sensitivity(3,2,:))’.*(p2(2)./sol2.Solution(3,:));
Figure(3)
t = tiledlayout(3,2);
title(t,[‘Parameter Sensitivity by Equation’,’$beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(t,’Time’,’Interpreter’,’latex’)
ylabel(t,’% Change in Eqn’,’Interpreter’,’latex’)
nexttile
plot(sol2.Time,U11)
title(‘$beta$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U12)
title(‘$gamma$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U21)
title(‘$beta$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U22)
title(‘$gamma$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U31)
title(‘$beta$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U32)
title(‘$gamma$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
function dydt = epidemic(t,y,p)
dydt = [0;0;0];
S = y(1);
I = y(2);
R = y(3);
N = S + I + R;
dSdt = -beta*(I*S)/N;
dIdt = beta*(I*S)/N – gamma*I;
dRdt = gamma*I;
end
endI want to perform the sensitivity analysis on the parameters of an ODE SIR model using normalized sensitivity function. I used the following code below. When it was run, I got this error: "undefined functionnor variable ‘p’, error in epidemic1 line8, F=ode45(@epidemic,ic,p)". How can I resolve it to get the plots?
My interest is to get the figure (3) i.e. The plot of nomalized sensitivity functions against time
function epidemic1()
clc
beta=0.4; gamma=0.04;
p1 = [beta gamma];
ic = [995;5;0];
F = ode45(@epidemic,ic,p);
sol1 = solve(F,0,80)
figure(1)
plot(sol1.Time,sol1.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’$beta=0.4$, $gamma=0.04$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
Figure(2)
p2 = [0.2 0.1];
F.Parameters = p2;
F.Sensitivity = odeSensitivity;
sol2 = solve(F,0,80)
plot(sol2.Time,sol2.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
U11 = squeeze(sol2.Sensitivity(1,1,:))’.*(p2(1)./sol2.Solution(1,:));
U12 = squeeze(sol2.Sensitivity(1,2,:))’.*(p2(2)./sol2.Solution(1,:));
U21 = squeeze(sol2.Sensitivity(2,1,:))’.*(p2(1)./sol2.Solution(2,:));
U22 = squeeze(sol2.Sensitivity(2,2,:))’.*(p2(2)./sol2.Solution(2,:));
U31 = squeeze(sol2.Sensitivity(3,1,:))’.*(p2(1)./sol2.Solution(3,:));
U32 = squeeze(sol2.Sensitivity(3,2,:))’.*(p2(2)./sol2.Solution(3,:));
Figure(3)
t = tiledlayout(3,2);
title(t,[‘Parameter Sensitivity by Equation’,’$beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(t,’Time’,’Interpreter’,’latex’)
ylabel(t,’% Change in Eqn’,’Interpreter’,’latex’)
nexttile
plot(sol2.Time,U11)
title(‘$beta$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U12)
title(‘$gamma$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U21)
title(‘$beta$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U22)
title(‘$gamma$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U31)
title(‘$beta$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U32)
title(‘$gamma$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
function dydt = epidemic(t,y,p)
dydt = [0;0;0];
S = y(1);
I = y(2);
R = y(3);
N = S + I + R;
dSdt = -beta*(I*S)/N;
dIdt = beta*(I*S)/N – gamma*I;
dRdt = gamma*I;
end
end I want to perform the sensitivity analysis on the parameters of an ODE SIR model using normalized sensitivity function. I used the following code below. When it was run, I got this error: "undefined functionnor variable ‘p’, error in epidemic1 line8, F=ode45(@epidemic,ic,p)". How can I resolve it to get the plots?
My interest is to get the figure (3) i.e. The plot of nomalized sensitivity functions against time
function epidemic1()
clc
beta=0.4; gamma=0.04;
p1 = [beta gamma];
ic = [995;5;0];
F = ode45(@epidemic,ic,p);
sol1 = solve(F,0,80)
figure(1)
plot(sol1.Time,sol1.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’$beta=0.4$, $gamma=0.04$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
Figure(2)
p2 = [0.2 0.1];
F.Parameters = p2;
F.Sensitivity = odeSensitivity;
sol2 = solve(F,0,80)
plot(sol2.Time,sol2.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
U11 = squeeze(sol2.Sensitivity(1,1,:))’.*(p2(1)./sol2.Solution(1,:));
U12 = squeeze(sol2.Sensitivity(1,2,:))’.*(p2(2)./sol2.Solution(1,:));
U21 = squeeze(sol2.Sensitivity(2,1,:))’.*(p2(1)./sol2.Solution(2,:));
U22 = squeeze(sol2.Sensitivity(2,2,:))’.*(p2(2)./sol2.Solution(2,:));
U31 = squeeze(sol2.Sensitivity(3,1,:))’.*(p2(1)./sol2.Solution(3,:));
U32 = squeeze(sol2.Sensitivity(3,2,:))’.*(p2(2)./sol2.Solution(3,:));
Figure(3)
t = tiledlayout(3,2);
title(t,[‘Parameter Sensitivity by Equation’,’$beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(t,’Time’,’Interpreter’,’latex’)
ylabel(t,’% Change in Eqn’,’Interpreter’,’latex’)
nexttile
plot(sol2.Time,U11)
title(‘$beta$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U12)
title(‘$gamma$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U21)
title(‘$beta$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U22)
title(‘$gamma$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U31)
title(‘$beta$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U32)
title(‘$gamma$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
function dydt = epidemic(t,y,p)
dydt = [0;0;0];
S = y(1);
I = y(2);
R = y(3);
N = S + I + R;
dSdt = -beta*(I*S)/N;
dIdt = beta*(I*S)/N – gamma*I;
dRdt = gamma*I;
end
end sensisitivity analysis, ode, normalized sensitivity MATLAB Answers — New Questions
Help: MS Word 365 document does not respond to footnote formatting procedure.
I have followed the steps as outlined in this MS video exactly, yet it has no effect on my document’s footnote numbers. MSWordVideo The document has nearly 200 pages with many footnotes. The footnote number font size was fine… and then for some reason they all changed when I was trying to format a bulleted list (had nothing to do with footnotes) and I am unable to get them back to the previous size or to change them at all.
I have followed the steps as outlined in this MS video exactly, yet it has no effect on my document’s footnote numbers. MSWordVideo The document has nearly 200 pages with many footnotes. The footnote number font size was fine… and then for some reason they all changed when I was trying to format a bulleted list (had nothing to do with footnotes) and I am unable to get them back to the previous size or to change them at all. Read More
When will the People Vertical (Organization level) become configurable?
All Out of the Box search verticals can be customized in the Search & Intelligence admin center, but not People.
We really need to be able to add refiners AND taylor the query in order to exclude some of the results
All Out of the Box search verticals can be customized in the Search & Intelligence admin center, but not People. We really need to be able to add refiners AND taylor the query in order to exclude some of the results Read More
Data is not getting stored as a web part properties, in single part app page in spfx.
I have created the spfx solution, which is organization chart, in that i am storing the data, in the manifest.json file as a webPart properties, but when i deploy that solution to the sharepoint online, and when i add that web part in the site page, it will add, when do the changes in the web part, it will save the changes, in the manifest.json file, but when i add the same web part, as a single part app page, it will work fine, but when i reload the page, it will not saving the data in manifest.json file, site will start from starting again.
The above one is the manifest.json file of the solution, where data is being stored
It is showing this popup message.
Please provide the solution for this???
I have created the spfx solution, which is organization chart, in that i am storing the data, in the manifest.json file as a webPart properties, but when i deploy that solution to the sharepoint online, and when i add that web part in the site page, it will add, when do the changes in the web part, it will save the changes, in the manifest.json file, but when i add the same web part, as a single part app page, it will work fine, but when i reload the page, it will not saving the data in manifest.json file, site will start from starting again. The above one is the manifest.json file of the solution, where data is being stored It is showing this popup message.Please provide the solution for this??? Read More