![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/474053/image.png)
Dimensional Problem with simple coefficient equation
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Kevin Zhou
il 22 Dic 2020
Commentato: Kevin Zhou
il 3 Gen 2021
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/467800/image.png)
I am trying to create this function in MATLAB. From a previous question, I have solved for a as "agrid2" and f(a) as "fx", whose dimensions are 600 by 1 and 600 by 2- these two vectors are absolutely correct:
%calculating gini coefficent
m=600;
for i=1:m %expanded length of kgrid of ai previously calculated in invarden.m
mu= sum(agrid2.*fx(m,:));
gini= sum(fx(m,1)*(fx(m,2))*abs(fx(m,1)-fx(m,2)))./(2*mu);
end
However, my code is returning all blank answers- what did I do wrong? Any advice is greatly appreciated!
0 Commenti
Risposta accettata
Prudhvi Peddagoni
il 30 Dic 2020
Hi,
For two summations, you will need two for loops. Also , you are not accumulating the sum. Variable gini is getting new value for every iteration. So you are losing the data from previous iterations.
For an equation like G=
, the code will be like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/474053/image.png)
sum=0;
for i = 1:40
for j = 50
sum = sum + (i+j);
end
end
G = sum;
Hope this helps
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!