Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
problam evaluating a simple calculation for a vector of values

Subject: problam evaluating a simple calculation for a vector of values

From: Arik g

Date: 8 Dec, 2008 13:20:18

Message: 1 of 5

i'm usin the Array multiply operator .* for a simple calculation on a vector of values.
this is done by a for-loop, 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 floating-double-array numbers in my PC.
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 1-3 - are now of different values, and are fluctuating in an increasung increment.
i couldn't find any bug or divide-by-zero 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?

Subject: problam evaluating a simple calculation for a vector of values

From: John D'Errico

Date: 8 Dec, 2008 13:48:01

Message: 2 of 5

"Arik g" <elalyg@gmail.com> wrote in message <ghj6ui$9m9$1@fred.mathworks.com>...
> i'm usin the Array multiply operator .* for a simple calculation on a vector of values.
> this is done by a for-loop, 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 floating-double-array numbers in my PC.
> 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 1-3 - are now of different values, and are fluctuating in an increasung increment.
> i couldn't find any bug or divide-by-zero 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?

Unless you show us an example, we cannot do
or say much to help you.

John

Subject: problam evaluating a simple calculation for a vector of values

From: Roger Stafford

Date: 8 Dec, 2008 17:26:02

Message: 3 of 5

"Arik g" <elalyg@gmail.com> wrote in message <ghj6ui$9m9$1@fred.mathworks.com>...
> .......
> 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 1-3 - are now of different values, and are fluctuating in an increasung increment.
> ......

  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 two-element array may show the two separate displays of 6.0000 and 6.0000e10, but together they show as:

 1e10 times 0.0000 6.0000

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.

Roger Stafford

Subject: problam evaluating a simple calculation for a vector of values

From: Arik g

Date: 9 Dec, 2008 09:55:03

Message: 4 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ghjlba$abl$1@fred.mathworks.com>...
> "Arik g" <elalyg@gmail.com> wrote in message <ghj6ui$9m9$1@fred.mathworks.com>...
> > .......
> > 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 1-3 - are now of different values, and are fluctuating in an increasung increment.
> > ......
>
> 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 two-element array may show the two separate displays of 6.0000 and 6.0000e10, but together they show as:
>
> 1e10 times 0.0000 6.0000
>
> 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.
>
> Roger Stafford





thanks for the quick reply. and sorry the the following long text, but i really need help in this:

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...?!?!?

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]


i'll try to explain it again: i have a rather simple calculation that is done iteratively in a for-loop. 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:
p1aD=p1aS.*dVal1a+p1bS.*(1-dVal1b).*(1-dispeCost);
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).

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).

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].

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 non-elegantly the aparent problem. but there remains 2 important questions:

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?
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?

many many thanks for the attentions
Arik

Subject: problam evaluating a simple calculation for a vector of values

From: Roger Stafford

Date: 9 Dec, 2008 18:07:01

Message: 5 of 5

"Arik g" <elalyg@gmail.com> wrote in message <ghlf9n$jtp$1@fred.mathworks.com>...
> .........
> 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].
> .........

  In any for-loop 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.

  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 for-loop code is written.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us