Creating a For loop with fzero having multiple variables and selecting at random an output value
Mostrar comentarios más antiguos
The problem is as follows:
Demand and supply in a given market interact in a way that we have three possible equilibrium prices (ptstar) for rt.
u= @(ptstar,rt) (ptstar.^(-1/9) + 2 + rt.* ptstar.^(-1) - ptstar.^(-8/9)) - (2+rt);
Above, you can see the equation which sets demand and supply equal by subtracting supply(2+rt) from demand and solving for zero.
The thing is there are 50 different time periods rt and I need to find the three equilibrium prices for each period(so a total of 150).
After this process, I need to select one value for ptstar of the three possible ones by setting equal probabilities to the maximum(first) and minimum(third) value of the equilibrium price.
Here is my approach( I have no idea how to handle the part with selecting one value for ptstar):
rbar=0.77;
a=6*10^-3;
b=0;
et=a.*randn(50,1)+b;
rt = rbar+et
for i=linspace(rt(1),rt(50),50)
u= @(ptstar,i) (ptstar.^(-1/9) + 2 + i .* ptstar.^(-1) - ptstar.^(-8/9)) - (2+i);
ptstarMax=fzero(u,[1.1, 1e4],[],i)
ptstarMiddle=fzero(u,[1],[],i)
ptstarMin=fzero(u,[0.1, 0.7],[],i)
end
rt is a column vector of 50 numbers following a random distribution with mean 0 and standard dev.6*10^-3 plus 0.77.
Sometimes I get a result, however, the ptstarMax values comein ascending order which makes no sense, because the values of rt are random and in no particular order..
I suspect there is a problem with the linspace function looping rt(1) to rt(50) through each fzero function
Finnaly, sometimes this gets printed: However, sometimes it doesn't appear:
Error using fzero (line 290)
The function values at the interval endpoints must differ in sign.
Error in try2 (line 12)
ptstarMin=fzero(u,[0.1, 0.7],[],i)
I really appreciate the help! Thanks a lot!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!