Need help with magnitude

I need help writing a function for magnitude. I commented it out to see if the polar coordinates would work but i still need to define magnitude before it will work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 #include<iostream>
#include<cmath>

using namespace std;


//double mag=sqrt((pow(x,2))+(pow(y,2)));
double Radius(double x, double y);
double Theta (double x, double y);

//............................................................

int main(void)
{
    double x = 0;
    double y = 0;
    double v=3.0, w=4.0;
    double m;
	
	

    cout << "Please enter the X coordinate: ";
    cin >> x;
    cout << "Please enter the Y coordinate: ";
    cin >> y;
	

    m=mag(x,y);       // you need to write this function!
    cout << "The magnitude of ( "<< x << " , "<< y <<" ) is: " << m << endl;
    
    m=mag(v,w);       // now get the magnitude of vector (v,w)
    cout << "The magnitude of ( "<< v << " , "<< w <<" ) is: " << m << endl;

}
    
       
    double r, theta;
    
    rect2polar(x,y,r,theta);
 
    cout << "the polar form of ( "<< x << " , "<< y <<" ) is: ( " << r << " , " << theta << " )"<<endl;
    rect2polar(v,w,r,theta);
 
    cout << "the polar form of ( "<< v << " , "<< w <<" ) is: ( " << r << " , " << theta << " )"<<endl;

    return 0;
}

//double mag=sqrt((pow(x,2))+(pow(y,2)))

	double Radius(double x, double y)
{
	double rad;
	rad = sqrt((pow(x,2))+(pow(y,2)));
	return rad;
}	
double Theta(double x, double y)
{
	double Thta;
	Thta = atan(y/x);
	return Thta;
}
Topic archived. No new replies allowed.