Why do I get incorrect output when I run a command like "number*sum(x{1}(1:end).^integer)" in MATLAB 7.12 (R2011a)?
2 views (last 30 days)
Show older comments
I get incorrect output (ans = 0) when I run the following code:
x{1} = [1 2 3 4 5];
mySum = sum( (x{1}(1:end)).^2 )
1 * sum( (x{1}(1:end)).^2 )
The result must match (ans = 55):
sum( (x{1}(1:end)).^2 )
The only difference is the 1 which is pre multiplied.
This appears to be an error in the parsing mechanism.
Accepted Answer
MathWorks Support Team
on 12 Apr 2012
This bug has been fixed in Release 2012a (R2012a). For previous product releases, read below for possible workarounds:
There is a bug in the way MATLAB 7.10 (R2010a) parses the commands.
Possible workarounds are as follows:
1) Use the undocumented FEATURE function
feature accel off
2) Use POWER instead of the operator.
1 * sum(power( (x{1}(1:end)),2) )
instead of
1 * sum( (x{1}(1:end)).^2 )
NOTE: This bug seems to be present only if
1) The power is integer.
2) END is used instead of the length of the vector.
0 Comments
More Answers (0)
See Also
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!