Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- temp trapecii(int k, double h) {
- struct temp tempY, tempY2;
- tempY.y1 = y[k].y1+ h * f1(y[k]);
- tempY.y2 = y[k].y2 + h * f2(y[k]);
- tempY.y3 = y[k].y3+ h * f3(y[k]);
- tempY.y4 = y[k].y4 + h * f4(y[k]);
- tempY2.y1 = y[k].y1 + h / 2 *(f1(y[k]) + f1(tempY));
- tempY2.y2 = y[k].y2 + h / 2 * (f2(y[k]) + f2(tempY));
- tempY2.y3 = y[k].y3 + h / 2 * (f3(y[k]) + f3(tempY));
- tempY2.y4 = y[k].y4 + h / 2 * (f4(y[k]) + f4(tempY));
- return tempY2;
- }
- void solveTrapecii(ostream &fout) {
- double x1 = x0, err, d = 0, h = h0;
- int k = 0;
- struct temp y1, y2, y3;
- x.push_back(x0);
- int start = clock();
- double hnew = h;
- while (x1 < xMax) {
- while (d < 1) {
- h = hnew;
- nr++;
- y3 = trapecii(k, 2 * h);
- y1 = trapecii(k, h);
- y.push_back(y1);
- y2 = trapecii(k + 1, h);
- err = abs(y2.y1 - y3.y1);
- err = max(err, abs(y2.y2 - y3.y2));
- err = max(err, abs(y2.y3 - y3.y3));
- err = max(err, abs(y2.y4 - y3.y4));
- d = sqrt(abs(tol / err));
- hnew = h * 0.8 * d;
- y.erase(y.end() - 1);
- }
- na++;
- nr--;
- d = 0.0;
- y.push_back(y2);
- x1 = x[k] + 2 * h;
- x.push_back(x1);
- k++;
- h = min(hnew, (xMax - x[x.size() - 1]) / 2);
- hnew = h;
- }
- int end = clock();
- fout << setprecision(2) << (double)(end - start) / CLOCKS_PER_SEC << endl;
- fout << na << ' ' << nr << ' ' << na + nr << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement