Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- struct Vector {
- double x, y;
- Vector() {x = y = 0;}
- Vector(double a, double b) : x(a), y(b) {}
- Vector operator * (const double k) {
- Vector c(x * k, y * k);
- return c;
- }
- Vector operator - (const Vector &a) {
- Vector c(x - a.x, y - a.y);
- return c;
- }
- };
- Vector df(Vector a) {
- Vector grad;
- grad.x = 2 * (sin(a.x + 1) - a.y - 1) * cos(a.x + 1) + 8 * a.x + 4 * cos(a.y) - 8;
- grad.y = -2 * sin(a.x + 1) + 2 * a.y + 2 - 2 * (2 * a.x + cos(a.y) - 2) * sin(a.y);
- return grad;
- }
- double norma(Vector a) { return sqrt(pow(a.x, 2)) + (pow(a.y, 2)); }
- void solve(double EPS, double I) {
- Vector prevX, x;
- int i = 0;
- double d;
- do {
- prevX = x;
- d = norma(df(x));
- x = prevX - df(prevX) * I;
- i++;
- } while (d >= EPS);
- cout << "Iteration :: " << i << "\t >>\tx, y = {" << x.x << ", " << x.y << "}";
- return;
- }
- int main() {
- solve(1e-4, 1e-3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement