find(V==max(V),1,'first') returns index that is way beyond the first index where X reaches the maximum
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
find(V==max(V),1,'first') returns index that is way beyond the first index where V reaches the maximum.
In the above picture, you can see that the curve reaches its maximum and plateaus. However, when I run find(X==max(X),1,'first') in the console, I get this:
Where's the error?
16 Commenti
Torsten
il 4 Ago 2022
Was I rounding my calculations? I have no idea! Can you please tell me how to calculate in full precision without rounding? In my code, I didn't manipulate anything related to precision.... or maybe I should have?...
You asked "is there a configuration to truncate values or maybe force the trapz function to generate truncated values?" and with my answer I meant: Don't generate truncated values - use trapz as before without truncating or rounding.
But why? can't floating numbers be equal? why wouldn't they?
x1 = 0.33333333333333;
x2 = 1/3;
x1 == x2
Here is a discussion about the subject:
Stephen23
il 4 Ago 2022
"But why? can't floating numbers be equal?
Of course they can be equal. That does not mean that they will be equal.
"why wouldn't they?"
Because of how floating point error accumulates during any arithmetic using binary floating point numbers.
Read this and you will understand why: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
Risposte (1)
Steven Lord
il 4 Ago 2022
What are the sizes of the variables involved in creating your plot above, and what is the exact syntax for the plot function that you used in creating it?
If the X data for your plot was not the integers 1 through the number of values in the Y data then the index of the point with X coordinate 363 may be greater than 363. In the example below, index is not 1 but the value stored in the X array at that index is 1.
X = 0:0.25:2
index = find(X == 1) % Will be > 1
coordinate = X(index) % Will be 1
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!