-
April 27th, 2016, 05:08 AM
#1
reason for a code written in C and matlab giving different output
The codes (C and matlab) are exactly same (operations wise) and same value of epsilon is used in both the codes. Still they give different output, what could be the reason for it.
-
April 27th, 2016, 05:52 AM
#2
Re: reason for a code written in C and matlab giving different output
1. What is "epsilon"?
2. What is the type of the "output"?
3. What was the "difference" between the "outputs"?
Victor Nijegorodov
-
April 28th, 2016, 11:14 PM
#3
Re: reason for a code written in C and matlab giving different output
1.This epsilon is used in if statements for making comparisons. epsilon in matlab is 2.2204e-16 .
I use " #define eps 2.2204e-16 " in C
2. The output is obtained by using arithmetic operations and comparisons on the initial data (which is taken to be exactly same for both C and Matlab code)
3. The contour plots of C and Matlab outputs differ slightly
-
April 29th, 2016, 02:10 AM
#4
Re: reason for a code written in C and matlab giving different output
Originally Posted by tangled09
3. The contour plots of C and Matlab outputs differ slightly
How slightly? Some numbers can't be represented exactly, so they will be rounded off. The deviation can then increase for every arithmetic operation.
-
April 29th, 2016, 03:24 AM
#5
Re: reason for a code written in C and matlab giving different output
What precision are you using for real numbers in c and in Matlab? In c/c++ there are several different precision types that can be used - eg float, double, long double.
For MS VS, see
https://msdn.microsoft.com/en-us/library/cc953fe1.aspx
https://msdn.microsoft.com/en-us/library/s3f49ktz.aspx
Also note that in c the ordering of expression evaluation can have an effect on the accuracy of the result.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|