Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<cmath>
- using namespace std;
- struct Vector {
- float x, y, z;
- };
- float norma(Vector X);
- Vector gradient(Vector X);
- float norma(Vector X) {
- return sqrt(pow(X.x,2)) + (pow(X.y,2)) + (pow(X.z,2));
- }
- Vector gradient(Vector X) {
- Vector grad;
- grad.x = 4*((pow(X.x,2))+2*X.y-3*X.z-0.9)*X.x+16*X.x-4*(pow(X.y,2))+4*X.z-24.84+12*X.y-4*(pow(X.z,2));
- grad.y = 4*(pow(X.x,2))+26*X.y-12*X.z-30.66-4*(2*X.x-(pow(X.y,2))+X.z-1.7)*X.y+12*X.x-6*(pow(X.z,2));
- grad.z = -6*(pow(X.x,2))-12*X.y+20*X.z+2.0+4*X.x-2*(pow(X.y,2))-4*(2*X.x+3*X.y-pow(X.z,2)-4.51)*X.z;
- return grad;
- }
- int main() {
- Vector X0, X1;
- float I = 0.001, eps = 0.0001, b = 0;
- X0.x = X0.y = X0.z = 0;
- X1.x = X1.y = X1.z = 0;
- while(norma(gradient(X1))>eps) {
- b++;
- if(b > 1) {
- X0 = X1;
- }
- X1.x = X0.x -I * gradient(X0).x;
- X1.y = X0.y -I * gradient(X0).y;
- X1.z = X0.z -I * gradient(X0).z;
- }
- cout << " Our roots are " << endl;
- cout << X1.x << endl << X1.y << endl << X1.z << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement