http://www.mathworks.com/matlabcentral/newsreader/view_thread/240636
MATLAB Central Newsreader  problam evaluating a simple calculation for a vector of values
Feed for thread: problam evaluating a simple calculation for a vector of values
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 08 Dec 2008 13:20:18 +0000
problam evaluating a simple calculation for a vector of values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/240636#615653
Arik g
i'm usin the Array multiply operator .* for a simple calculation on a vector of values.<br>
this is done by a forloop, that runs around 5000 times. each run, the calculation includes several multiplications of values usually smaller than 1, with the values in the vector. threre is no interaction between the values, naturally. the thing is, that as the runs go forward, the values multipling the vector get r e a l l y s m a l l, around 10^100 or 10^200, nearing the 10^324 limit for the floatingdoublearray numbers in my PC.<br>
and now the strange thing: when the vector has 1, 2 or 3 values, the claculation results for those values is certain curve. when the vector has 4 or more values, the outcome changes and the same curves and results  corresponding to the values that were in the vector of size 13  are now of different values, and are fluctuating in an increasung increment.<br>
i couldn't find any bug or dividebyzero which wasn't avoided (although i'm not that experienced, so anything's possible)  so can anyone tell me what is the problem? is it in the machine, the program or a question of scaling the values in the calculation beforw outputing them?

Mon, 08 Dec 2008 13:48:01 +0000
Re: problam evaluating a simple calculation for a vector of values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/240636#615664
John D'Errico
"Arik g" <elalyg@gmail.com> wrote in message <ghj6ui$9m9$1@fred.mathworks.com>...<br>
> i'm usin the Array multiply operator .* for a simple calculation on a vector of values.<br>
> this is done by a forloop, that runs around 5000 times. each run, the calculation includes several multiplications of values usually smaller than 1, with the values in the vector. threre is no interaction between the values, naturally. the thing is, that as the runs go forward, the values multipling the vector get r e a l l y s m a l l, around 10^100 or 10^200, nearing the 10^324 limit for the floatingdoublearray numbers in my PC.<br>
> and now the strange thing: when the vector has 1, 2 or 3 values, the claculation results for those values is certain curve. when the vector has 4 or more values, the outcome changes and the same curves and results  corresponding to the values that were in the vector of size 13  are now of different values, and are fluctuating in an increasung increment.<br>
> i couldn't find any bug or dividebyzero which wasn't avoided (although i'm not that experienced, so anything's possible)  so can anyone tell me what is the problem? is it in the machine, the program or a question of scaling the values in the calculation beforw outputing them?<br>
<br>
Unless you show us an example, we cannot do<br>
or say much to help you.<br>
<br>
John

Mon, 08 Dec 2008 17:26:02 +0000
Re: problam evaluating a simple calculation for a vector of values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/240636#615719
Roger Stafford
"Arik g" <elalyg@gmail.com> wrote in message <ghj6ui$9m9$1@fred.mathworks.com>...<br>
> .......<br>
> and now the strange thing: when the vector has 1, 2 or 3 values, the claculation results for those values is certain curve. when the vector has 4 or more values, the outcome changes and the same curves and results  corresponding to the values that were in the vector of size 13  are now of different values, and are fluctuating in an increasung increment.<br>
> ......<br>
<br>
It sounds to me as though your problem is possibly that of display and not the numbers' values themselves. The displayed values for a vector will be arranged to suit the largest value present when they are displayed together. For example if you are using format short, a twoelement array may show the two separate displays of 6.0000 and 6.0000e10, but together they show as:<br>
<br>
1e10 times 0.0000 6.0000<br>
<br>
The first element really has the value of 6 but its displayed value looks like a zero in the presence of the 1e10 exponent factor.<br>
<br>
Roger Stafford

Tue, 09 Dec 2008 09:55:03 +0000
Re: problam evaluating a simple calculation for a vector of values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/240636#615871
Arik g
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ghjlba$abl$1@fred.mathworks.com>...<br>
> "Arik g" <elalyg@gmail.com> wrote in message <ghj6ui$9m9$1@fred.mathworks.com>...<br>
> > .......<br>
> > and now the strange thing: when the vector has 1, 2 or 3 values, the claculation results for those values is certain curve. when the vector has 4 or more values, the outcome changes and the same curves and results  corresponding to the values that were in the vector of size 13  are now of different values, and are fluctuating in an increasung increment.<br>
> > ......<br>
> <br>
> It sounds to me as though your problem is possibly that of display and not the numbers' values themselves. The displayed values for a vector will be arranged to suit the largest value present when they are displayed together. For example if you are using format short, a twoelement array may show the two separate displays of 6.0000 and 6.0000e10, but together they show as:<br>
> <br>
> 1e10 times 0.0000 6.0000<br>
> <br>
> The first element really has the value of 6 but its displayed value looks like a zero in the presence of the 1e10 exponent factor.<br>
> <br>
> Roger Stafford<br>
<br>
<br>
<br>
<br>
<br>
thanks for the quick reply. and sorry the the following long text, but i really need help in this:<br>
<br>
first, a correction for what is the real problem: i notices that when the parameter's values are close to each other, the curve is OK, but when they are far (0 and 0.3, for example) then the problem starts, results change and the curve starts to fluctuate...?!?!?<br>
<br>
however, i don't think it is a display problem  i've changed the preferences to "long e loose" for display in the command line. and also the problem is that the curve plot of the results (i do not know how to control display problems there, if you think thats the problem) shows the same problem: from being a smooth curve, when thatere are values which are close to each other [0,0.02,...,0.1]<br>
<br>
<br>
i'll try to explain it again: i have a rather simple calculation that is done iteratively in a forloop. the calculation includes a parameter we'll name "dispeCost". this parameter can have more than one value, naturally, because i want to see its influence on the results. so, it can be a vector of values. the calculation is somthing like: <br>
p1aD=p1aS.*dVal1a+p1bS.*(1dVal1b).*(1dispeCost);<br>
and all through the functions that are called through the process, i use ".*"  Array Multiply, as ,mentioned before. and otherwise, there shouldn't be any interaction between the differnet values of dispeCost (i've checked through the function to make sure i didn't do a stupid error).<br>
<br>
i guess it is important to note that the values of the differnet p1a,p1aD etc are between 0 and 1, and can get really small when nearing 0  around 10^100 and less (i understood Matlab's limit is 10^324, so i have a threshold to avoid "divide by zero" cases).<br>
<br>
so when i run it for one value of dispeCost at a time, there's no aparant problem. when i run it for 2 or more, then the differnce between the extreme values kicks into action: if i run it for [0,0.1]  OK. for [0,0.05,0.1], also OK, and also OK for [0.005,0.1,0.3]. but for [0,0.1,0.3] or for [0,0.3] NOT OK. the results for values 0 and 0.1 change this time from what they were when i ran them seperately, or as a couple [0,0.1].<br>
<br>
therefor i guessed that the problem is the i can do calculations for values that are close to each other, OR at least vectors that do not include the value 0 in them. so ok, i can avoid nonelegantly the aparent problem. but there remains 2 important questions:<br>
<br>
1)can i do it elegantly, and include 0 in the vector of values of the parameter "dispeCost"? what do i need to do or to change in the settings to do so?<br>
2)does this problem i've encountered indicated a serious bug in my calculations, or is it just a problem of the extreme case of 0? in other words  can i be sure that the calculations for values other than 0 are ok?<br>
<br>
many many thanks for the attentions<br>
Arik

Tue, 09 Dec 2008 18:07:01 +0000
Re: problam evaluating a simple calculation for a vector of values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/240636#615967
Roger Stafford
"Arik g" <elalyg@gmail.com> wrote in message <ghlf9n$jtp$1@fred.mathworks.com>...<br>
> .........<br>
> so when i run it for one value of dispeCost at a time, there's no aparant problem. when i run it for 2 or more, then the differnce between the extreme values kicks into action: if i run it for [0,0.1]  OK. for [0,0.05,0.1], also OK, and also OK for [0.005,0.1,0.3]. but for [0,0.1,0.3] or for [0,0.3] NOT OK. the results for values 0 and 0.1 change this time from what they were when i ran them seperately, or as a couple [0,0.1].<br>
> .........<br>
<br>
In any forloop procedure that I am aware of, the results of an iterated calculation should be precisely the same as those one would obtain doing them one at a time, provided that the input numerical quantities used are exactly the same and that there is no "feedback" between successive computations where one result depends on previous results.<br>
<br>
If you think you have an example to the contrary, you should present it with the all the numerical values specified so that others can check it for themselves. I think this is the only way you can get the assistance you are asking for. Also it would be advisable to make your example as brief as possible. You stated that you ran into trouble with a vector with only two values for dispeCost: [0,0.3]. How about showing us that one in detail? That means you would have to exactly specify what the values of p1aS, dVal1a, p1bS, and dVal1b are for each point of dispeCost and exactly how your forloop code is written.<br>
<br>
Roger Stafford