Hallo,
I have been trying to to generate a 100x100 table that includes the solution of a certain equation for 10000 different inputs.
My m.file has a double counter i and j and loops as follows
clear clc
W=zeros(100,100);
for i=1:100
for j=1:100
W(i,j)=double(cost_factor(i/100,j/100,2));
end
end
The function cost factor is called at every iteration and its source code is provided bellow:
function [w] = cost_factor(b,b_plus,x ) %This function is a subroutine that computes the cost factor w as a function of b,b_dash,x
% Inputs
% b previous day's portfolio % b_plus this day's portfolio % x previous day's stock price relative (x=2 or x=0.5)
% Outputs
% w present cost relative
c_p=0.01; r=0; syms w assume(1/(1+c_p)<=w<=1)
w=solve(w+0.5*c_p*(abs(b_plus*w-b*x/(b*x+(1-b)*exp(r)))+(b_plus*w-b*x/(b*x+(1-b)*exp(r))))+...
0.5*c_p*abs((1-b_plus)*w-(1-b)*exp(r)/(b*x+(1-b)*exp(r))+(1-b_plus)*w-(1-b)*exp(r)/(b*x+(1-b)*exp(r)))==1,w);
end
Everything seems to work fine when the first argument cost factor's inputs is larger than the second but in some of the cases where the converse is true I get the message 'Warning: Explicit solution could not be found. '. More specifically, I get this message when the difference b_plus-b>=0.48. So, my loop stops at W(1,52). Finally, note that b and b_plus are assigned values in [0,1] by the counters. Anyone that could enlighten me on the issue?
Thanks in advance,
Konstantinos
No products are associated with this question.
1 Comment
Direct link to this comment:
http://www.mathworks.com/matlabcentral/answers/80831#comment_157862
At the command prompt, please command
and then run your code. When it stops in the debugger, please use dbstep until you get back to the cost_factor routine. Then, please show us the expression
Caution: it is safer to write out that compound assumption in full,