From: Alex Buisson on
hi,
i'm beginner with Mathlab, and my current job is just to rewrite a mathlab program with C/C++ language.

During this work, i have rewrite several mathlab function and check my implementation vs Mathlab output using a precision of 1e-6.

this criteria work well until the end of the program, because result of computation which are 'double' are dump into a file as 'int32'.

I use a round in both implementation (mathlab & C++), but sometimes there are some variations at more than 1e-6 which lead to rounding error.

As i cannot "really" increase or decrease my compiler and FPU accuracy, i think i can control the mathlab accuracy to fit with C++/compiler/ia32 constraint.

Have you a way to do this ?
NB: i use Mathlab R2010a and my compiler is Visual Studio 2008 (floating optimization are disable through /fp:precise).

All help would be welcome.
Thanks.
From: Rune Allnor on
On 20 Mai, 13:32, "Alex Buisson" <alex.buis...(a)gmail.com> wrote:
> hi,
> i'm beginner with Mathlab, and my current job is just to rewrite a mathlab program with C/C++ language.
>
> During this work, i have rewrite several mathlab function and check my implementation vs Mathlab output using a precision of 1e-6.

The differences you see are due to your lack of skills in numerical
computing. Writing numerical software that works well is an art that
requires years of deliberate studies, training and practice to
master.
Don't expect to reproduce the results from matlab without investing
the several years worth of effort required to learn numerical
programming.

Rune
From: Jan Simon on
Dear Alex!

> During this work, i have rewrite several mathlab function and check my implementation vs Mathlab output using a precision of 1e-6.
>
> this criteria work well until the end of the program, because result of computation which are 'double' are dump into a file as 'int32'.

After Rune's charming advice to study the problem for some years, I'd suggest to dumb DOUBLE variables as DOUBLEs - rounding to int32 wastes the computational accuracy.

The "precision of 1e-6" is not an exact description. If you want to check the caclulation of SIN and COS, an *absolute* precision of 1e-6 is very rough. If you compare the result of 10^31.1 the absolute precision of 1e-6 is meaningless. Can you give us some more details?

Jan
From: Rune Allnor on
On 20 Mai, 15:22, "Jan Simon" <matlab.THIS_Y...(a)nMINUSsimon.de> wrote:
> Dear Alex!
>
> > During this work, i have rewrite several mathlab function and check my implementation vs Mathlab output using a precision of 1e-6.
>
> > this criteria work well until the end of the program, because result of computation which are 'double' are dump into a file as 'int32'.
>
> After Rune's charming advice to study the problem for some years,

Only a fool would ridicule that advice.

> I'd suggest to dumb DOUBLE variables as DOUBLEs  - rounding to int32 wastes the computational accuracy.

Sure. But assuming the OP knows what he is doing and why he wants
INTs (I know...), there is little more to do than actually learning
how to implement numerics. Which brings us straight back to square 2.

Rune
From: Jan Simon on
Dear Rune!

> > > During this work, i have rewrite several mathlab function and check my implementation vs Mathlab output using a precision of 1e-6.
> > > this criteria work well until the end of the program, because result of computation which are 'double' are dump into a file as 'int32'.
> >
> > After Rune's charming advice to study the problem for some years,
>
> Only a fool would ridicule that advice.

The OP "thinks he can control the mathlab accuracy to fit with C++/compiler/ia32 constraint". He will need a more practical advice than starting to study numerics for years: You cannot control the accuracy of Matlab. If two (correct) implementations of an algorithm reply different values, this is caused by the limited precision of floating point calculations.
E.g. look at Matlab's ASIN, which uses the C-implementation from FDLIBM (www.netlib.org). But if you compile the same source with BCC, OWC, LCC, MSVC compilers, you get slightly different results!

> Which brings us straight back to square 2.

Square 2 is 4 - no difference if it is written as DOUBLE or INT32.

Jan
 |  Next  |  Last
Pages: 1 2 3 4
Prev: exemple for mlp code
Next: Learning Fortran