Subtracting two values that are very small
Show older comments
I'm subtracting two variables (R1 and R2) that are around a magnitude of e-3. I work out a difference between them (Diff = R2 - R1) but my Diff variable outputs as 0 for the whole matrix. I am trying to plot Diff on a plot. How can I make Diff not output as all 0's? Thank you.
R1 = [0.00212278260869565 0.00212931740869565 0.00213585398260870 0.00214239233043478 0.00214893245217391 0.00215547434782609 0.00216201801739130 0.00216856346086957 0.00217511067826087 0.00218165966956522 0.00218821043478261 0.00219476297391304 0.00220131728695652 0.00220787337391304 0.00221443123478261 0.00222099086956522 0.00222755227826087 0.00223411546086957 0.00224068041739130 0.00224724714782609 0.00225381565217391]
R2 = [0.00212278260869565 0.00212931740869565 0.00213585398260870 0.00214239233043478 0.00214893245217391 0.00215547434782609 0.00216201801739130 0.00216856346086957 0.00217511067826087 0.00218165966956522 0.00218821043478261 0.00219476297391304 0.00220131728695652 0.00220787337391304 0.00221443123478261 0.00222099086956522 0.00222755227826087 0.00223411546086957 0.00224068041739130 0.00224724714782609 0.00225381565217391]
Diff = R2 - R1
4 Comments
William Rose
on 11 Feb 2022
@Muhammad Choudhury, R1 and R2 appear identical at the 10^-17 level. Why do you think they are different? It looks to me like R1-R2 is in fact a vector of zeros.
R1 = [0.00212278260869565 0.00212931740869565 0.00213585398260870 0.00214239233043478 0.00214893245217391 0.00215547434782609 0.00216201801739130 0.00216856346086957 0.00217511067826087 0.00218165966956522 0.00218821043478261 0.00219476297391304 0.00220131728695652 0.00220787337391304 0.00221443123478261 0.00222099086956522 0.00222755227826087 0.00223411546086957 0.00224068041739130 0.00224724714782609 0.00225381565217391];
R2 = [0.00212278260869565 0.00212931740869565 0.00213585398260870 0.00214239233043478 0.00214893245217391 0.00215547434782609 0.00216201801739130 0.00216856346086957 0.00217511067826087 0.00218165966956522 0.00218821043478261 0.00219476297391304 0.00220131728695652 0.00220787337391304 0.00221443123478261 0.00222099086956522 0.00222755227826087 0.00223411546086957 0.00224068041739130 0.00224724714782609 0.00225381565217391];
disp(max(abs(R2 - R1)))
Muhammad Choudhury
on 11 Feb 2022
Edited: Muhammad Choudhury
on 11 Feb 2022
William Rose
on 11 Feb 2022
@Muhammad Choudhury, if they were different then the vecotr
R2mR1=R2-R1;
wil have the correct difference.
I would not use
diff=R2-R1;
because there is a built-in function called diff() that computes the successive differences of a vector or array.
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!