Willkommen ~Gast!
Registrieren || Einloggen || Hilfe/FAQ || Staff
Probleme mit der Registrierung im Forum? Melde dich unter registerEin Bild.
Autor Beitrag
000
16.11.2002, 17:02
ScyTheMan
Moderator


Hi
ich hab ein kleines Problem beim Berechnen des arcusTangens in C++. Und zwar wird nicht arcusTangens berechnet sondern nur Tangens. Ich weis nicht was ich falsch gemacht habe, vielleicht könnt ihr mir helfen? Hier der code:
Quellcode:#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    const double PI = 3.14159265358979323846;
    const double GRAD=PI/180;
    double Winkel;
    double a,b;

    a=12.7;
    b=4.9;

    Winkel=a/b;
    cout<<"ArcusTangens("<<Winkel<<" Grad) = "<<atan(Winkel*GRAD)<<endl;
}

[edit]
ach ja, ich benutze M$ Visual C++ 6.0

--

http://choerbaert.org
Ein Gespenst geht um im Netz - das Gespenst des Open Source
csndr


Dieser Beitrag wurde am 16.11.2002 um 17:05 von - [ ScyTheMan ] - bearbeitet.
zum Seitenanfang zum Seitenende Profil || Suche
001
16.11.2002, 22:15
Kriz



atan, atan2
Calculates the arctangent of x (atan) or the arctangent of y/x (atan2).

double atan( double x );

double atan2( double y, double x );

Routine Required Header Compatibility
atan <math.h> ANSI, Win 95, Win NT
atan2 <math.h> ANSI, Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

atan returns the arctangent of x. atan2 returns the arctangent of y/x. If x is 0, atan returns 0. If both parameters of atan2 are 0, the function returns 0. You can modify error handling by using the _matherr routine. atan returns a value in the range –ð/2 to ð/2 radians; atan2 returns a value in the range –ð to ð radians, using the signs of both parameters to determine the quadrant of the return value.

Parameters

x, y

Any numbers

Remarks

The atan function calculates the arctangent of x. atan2 calculates the arctangent of y/x. atan2 is well defined for every point other than the origin, even if x equals 0 and y does not equal 0.

Example

/* ATAN.C: This program calculates
* the arctangent of 1 and -1.
*/

#include <math.h>
#include <stdio.h>
#include <errno.h>

void main( void )
{
double x1, x2, y;

printf( "Enter a real number: " );
scanf( "%lf", &x1 );
y = atan( x1 );
printf( "Arctangent of %f: %f\n", x1, y );
printf( "Enter a second real number: " );
scanf( "%lf", &x2 );
y = atan2( x1, x2 );
printf( "Arctangent of %f / %f: %f\n", x1, x2, y );
}

Output

Enter a real number: -862.42
Arctangent of -862.420000: -1.569637
Enter a second real number: 78.5149
Arctangent of -862.420000 / 78.514900: -1.480006

--

K:R-I)Z++
"CSS ist cascading style sheets. Und nicht so'n Ranzspiel." - dp
In memory of Voice († 2005/03/30)

zum Seitenanfang zum Seitenende Profil || Suche
002
16.11.2002, 22:44
Leviathan



@kriz: da gehören aber quote-tags drum...

@problem: arcustanges bekommt als argument einen bruch, keinen winkel. die rückgabe ist ein winkel, und zwar in der einheit radiant. du nimmt aber die umrechnung von altgrad in radiant am argument des arcustangens vor, du rechnest also einen bruch (genauer: den quotienten aus den beiden katheten) von altgrad in radiant um, obwohl er einheitenlos ist.

Quellcode:
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    const double PI = 3.14159265358979323846;
    const double GRAD=PI/180;
    double kq;    /*die bezeichnung "winkel" ist hier nicht angebracht, ich nehme hier mal kathetenquotient kq als bezeichnung*/
    double a,b;

    a=12.7;
    b=4.9;

    kq=a/b;
    cout<<"ArcusTangens("<<kq<<" Grad) = "<<atan(kq)<<" = "<<atan(kq)/GRAD<<"°\n";
}

kq kannste dir aber sparen wenn du atan2 verwendest (unnütz, dafür einen neuen bezeichner einzuführen, ich hätte ja arc einfach überladen...):

Quellcode:
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    const double PI = 3.14159265358979323846;
    const double GRAD=PI/180;
    double a,b;

    a=12.7;
    b=4.9;

    cout<<"ArcusTangens("<<kq<<" Grad) = "<<atan2(a,b)<<" = "<<atan2(a,b)/GRAD<<"°\n";
}

der arcustangens ist aber auch über den arcussinus berechenbar:

Quellcode:
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    const double PI = 3.14159265358979323846;
    const double GRAD=PI/180;
    double kq;    /*die bezeichnung "winkel" ist hier nicht angebracht, ich nehme hier mal kathetenquotient kq als bezeichnung*/
    double a,b;

    a=12.7;
    b=4.9;

    kq=a/b;
    cout<<"ArcusTangens("<<kq<<" Grad) = "<<asin(kq/sqrt(1-kq*kq))<<" = "<<atan(kq/sqrt(1-kq*kq))/GRAD<<"°\n";
}

--

Entities: HL | HL²
Kompilierfehler
r_speeds | mehr über r_speeds

zum Seitenanfang zum Seitenende Profil || Suche
003
16.11.2002, 22:51
ScyTheMan
Moderator


big thx an beide!

--

http://choerbaert.org
Ein Gespenst geht um im Netz - das Gespenst des Open Source
csndr

zum Seitenanfang zum Seitenende Profil || Suche