I need to write the code for solving a simple equation, which should contain arcsin and arccos.
Formulas
F = cos^2(p(x)) + sin^2(p(y) + p(z)
p(k) = arccos(a * k) + arcsin(k)
Here is the code I wrote for solving it, but it gives -nan Ind
as output. However, when I fix acos
and asin
to just cos
and sin
, everything works.
Expected input:
x = 1.20
y = 3.05
z = 2.00
Code
#include <iostream>
#include <math.h>
using namespace std;
const double a = 0.01;
double p(double k) {
double p1;
p1 = acos(a * k) + asin(k);
return (p1);
}
int main() {
double x;
double y;
double z;
double F;
cout << "x = "; cin >> x;
cout << "y = "; cin >> y;
cout << "z = "; cin >> z;
F = pow(cos(p(x)), 2) + pow(sin(p(y)), 2) + p(z);
cout << "F = " << F << endl;
return 0;
}
The OUTPUT range of SIN and COS is [-1, +1]. That means the INPUT range of ARC (inverse) sin is [-1, +1]. You are trying to do asin(1.2), which probably yields NaN.