A
arkkimede
Hello!
I need a little help with a numerical problem about the
function pow.
In the following a simple c++ code:
----------------------------------------------start code
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <complex>
using namespace std;
main()
{
complex<long double> a;
complex<long double> b1,b2,b3,b4;
complex<long double> j;
long double x = .1L;
j = complex<long double>(0,1);
a = exp(j);
b1 = exp(j/x);
b2 = pow(b1, x);
b3 = pow(exp(j/x ), x);
b4 = a - b3;
printf("x = +0.1L\n");
printf("a = exp(j) = %+30.25lle %+30.25lle
\n",a.real(), a.imag());
printf("b1 = exp(j/x) = %+30.25lle %+30.25lle
\n",b1.real(), b1.imag());
printf("b2 = pow(b2, x) = %+30.25lle %+30.25lle \n",b2.real
(), b2.imag());
printf("b3 = pow(exp(j/x), x) = %+30.25lle %+30.25lle \n",b3.real
(), b3.imag());
printf("b4 = a - b3 = %+30.25lle %+30.25lle\n",b4.real
(), b4.imag());
}
---------------------------------stop code
My problem is that, for well know math rules, b4 could be 0 or a
number very little (10^-7).
The output are:
risultato e' il seguente:
x = +0.1L
a = exp(j) = +5.4030230586813971741400736e-01
+8.4147098480789650666459081e-01
b1 = exp(j/x) = -8.3907152907645245226058231e-01
-5.4402111088936981343191709e-01
b2 = pow(b2, x) = +9.6724905798807620156166964e-01
-2.5382919418612824645313519e-01
b3 = pow(exp(j/x), x) = +9.6724905798807620156166964e-01
-2.5382919418612824645313519e-01
b4 = a - b3 = -4.2694675211993648414766228e-01
+1.0953001789940247530635159e+00
This version of code is with long double (sizeof(long double)=12Bytes
= 96 bits) to increase precision.
In the original version there is only complex.
Could you advice me how to solve this problem ?
TIA
I need a little help with a numerical problem about the
function pow.
In the following a simple c++ code:
----------------------------------------------start code
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <complex>
using namespace std;
main()
{
complex<long double> a;
complex<long double> b1,b2,b3,b4;
complex<long double> j;
long double x = .1L;
j = complex<long double>(0,1);
a = exp(j);
b1 = exp(j/x);
b2 = pow(b1, x);
b3 = pow(exp(j/x ), x);
b4 = a - b3;
printf("x = +0.1L\n");
printf("a = exp(j) = %+30.25lle %+30.25lle
\n",a.real(), a.imag());
printf("b1 = exp(j/x) = %+30.25lle %+30.25lle
\n",b1.real(), b1.imag());
printf("b2 = pow(b2, x) = %+30.25lle %+30.25lle \n",b2.real
(), b2.imag());
printf("b3 = pow(exp(j/x), x) = %+30.25lle %+30.25lle \n",b3.real
(), b3.imag());
printf("b4 = a - b3 = %+30.25lle %+30.25lle\n",b4.real
(), b4.imag());
}
---------------------------------stop code
My problem is that, for well know math rules, b4 could be 0 or a
number very little (10^-7).
The output are:
risultato e' il seguente:
x = +0.1L
a = exp(j) = +5.4030230586813971741400736e-01
+8.4147098480789650666459081e-01
b1 = exp(j/x) = -8.3907152907645245226058231e-01
-5.4402111088936981343191709e-01
b2 = pow(b2, x) = +9.6724905798807620156166964e-01
-2.5382919418612824645313519e-01
b3 = pow(exp(j/x), x) = +9.6724905798807620156166964e-01
-2.5382919418612824645313519e-01
b4 = a - b3 = -4.2694675211993648414766228e-01
+1.0953001789940247530635159e+00
This version of code is with long double (sizeof(long double)=12Bytes
= 96 bits) to increase precision.
In the original version there is only complex.
Could you advice me how to solve this problem ?
TIA