Matrix inversion and summation
Afficher commentaires plus anciens
Hi all, can anyone help me to explain the mistake in my code below? The problem is as follow:
- The following parameter is assumed,
lma = 3;
ma = zeros(1,lma);
ma(2) = -0.2;
ma(lma) = -0.01;
- The parameter is then used to calculate the coordinate z using the following equation,

where z = x + i*y (complex number)
dumZ = 0;
sumdumZ = 0;
theta = linspace(0,2*pi,37);
xi = exp(1i.*theta);
for ii=1:length(theta)
for jj=1:lma
dumZ = ma(jj).*xi(ii).^jj;
sumdumZ = sumdumZ + dumZ;
end
zcon(ii) = 1./xi(ii)+sumdumZ;
dumZ = 0;
sumdumZ = 0;
end
zcon=zcon';
The following profile is obtained by plotting zcon,

- Now, using the hypothetical data above, i.e. the zcon, I want to back-calculate the variable "ma" or "alpha" as shown in the equation above. To do this, I first created a matrix A, which essentially a matrix containing all the constants. The following code is used to generate matrix A with 370 terms,
lx = length(zcon);
N = 10*37;
A = zeros(lx,N);
for ii=1:lx
for jj=1:N
A(ii,jj) = xi(ii).^jj;
end
end
A=[1./xi' A]; % insert a new colum to the left containing the 1/xi(ii) into the existing matrix A;
- Then the variable "ma" or "alpha" can be easily obtained using the following operation in Matlab,
maiter = A\zcon;
which give me a [370 x 1] matrix. To validate this, I again calculate the "predicted" z using the following code:
zdirect = A*maiter;
Which results an exactly the same curve (as expected) as shown below,

Now, coming to my question. Instead of using a direct calculation as shown above, i.e. the code "zdirect = A*maiter, instead I would like to manually use summation to calculate the "z" for each "theta" using the code below. Somehow, I could not get it right and cannot find the mistake. Below is the code that I used to calculate "z"
dumZ = 0;
sumdumZ = 0;
pow = [-1 1:1:N];
for ii=1:length(theta)
for jj=1:length(maiter)
dumZ = maiter(jj).*xi(ii).^pow(jj);
sumdumZ = sumdumZ + dumZ;
end
ziter(ii) = sumdumZ;
dumZ = 0;
sumdumZ = 0;
end
Instead, this is what I got,

Can someone please help me?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!