Borrar filtros
Borrar filtros

Dimensional Problem with simple coefficient equation

5 visualizaciones (últimos 30 días)
Kevin Zhou
Kevin Zhou el 22 de Dic. de 2020
Comentada: Kevin Zhou el 3 de En. de 2021
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
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);
However, my code is returning all blank answers- what did I do wrong? Any advice is greatly appreciated!

Respuesta aceptada

Prudhvi Peddagoni
Prudhvi Peddagoni el 30 de Dic. de 2020
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:
for i = 1:40
for j = 50
sum = sum + (i+j);
G = sum;
Hope this helps

Más respuestas (0)


Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by