int main () {
    double epsilon, root;
    printf("Enter tolerance: ");
    scanf("%lf", &epsilon);

    printf("Enter n: ");
    scanf("%lf", &N);
    printf("Enter c: ");
    scanf("%lf", &C);

    if (newton_method(C / 2, epsilon, m, m_d, MAX_TRIES, &root))
        printf("m(%.7f) = %e\n", root, m(root));

    //printf("Funcion g\n");
    //if (newton_method(1.5, epsilon, g, g_d, MAX_TRIES, &root))
    //    printf("  g(%.7f) = %e\n", root, g(root));

    //printf("Funcion h\n");
    //if (newton_method(-4, epsilon, h, h_d, MAX_TRIES, &root))
    //    printf("  h(%.7f) = %e\n", root, h(root));

    //printf("Funcion func\n");
    //if (newton_method(0.5, epsilon, func, func_d, MAX_TRIES, &root))
    //    printf("  h(%.7f) = %e\n", root, func(root));

    return 0;
}
Пример #2
0
int main()
{
   newton_method(-2, -1);
   return 0;
}
Пример #3
0
int main()
{
   newton_method(0.001, .1);
   return 0;
}
Пример #4
0
int main()
{
   newton_method(0, 1);
   return 0;
}
Пример #5
0
//
// FUNCTION: WndProc (HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Process the message in the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - draw the main window
// WM_DESTROY - send a message to exit and return
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            switch (wmId)
            {
			case ID_COMBO:
				if (HIWORD(wParam) == CBN_SELCHANGE)
				{
					free(Array);
					currentFunction = getNewCurrentItem(lParam);
					Array = createSequence();
				}
				break;
			case ID_EDITBEGINX:
				if (HIWORD(wParam) == EN_CHANGE)
				{
					free(Array);
					Array = createSequence();
				}
				break;
			case ID_BUTTONAPPLY:
				if (HIWORD(wParam) == BN_CLICKED)
				{
					TCHAR buf[10];
					SearchX = _wtof(valueFromTextField(ID_SEARCHX, buf));
					Polynom = _wtoi(valueFromTextField(ID_POLYNOM, buf));
					newtonY = newton_method(SearchX, Polynom);
					splinesY = splines_method(SearchX);
					RealY = myFunc()(SearchX);
					InvalidateRect(hWnd, 0, true);
				}
				break;
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
			MoveToEx(hdc, 240, 15, NULL);
			LineTo(hdc, 240, 600);
			
			swprintf(out, L"Range: %d-%d; Newton method:  %2.9f ; Splines method:  %2.9f ; Real value: %2.9f", range.down, range.up, newtonY, splinesY, RealY);
			TextOutW(hdc, 260, 50, out, wcslen(out));
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
		free(Array);
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Пример #6
0
//
// FUNCTION: InitInstance (HINSTANCE, int)
//
// PURPOSE: Saves instance processing and creates the main window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // Save the instance handle in a global variable

   hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   if (!hWnd)
   {
      return FALSE;
   }

   LV LVSettings = {
	   15,											// X position
	   45,											// Y position
	   210,											// width
	   500,											// height
	   3,											// amount of columns
	   { TEXT("N"), TEXT("X"), TEXT("Y") },			// name of columns
	   70											// width of column
   };

   hwndListView = createLV(LVSettings);

   CB CBSettings = {
	   15,											// X position
	   15,											// Y position
	   100,											// width
	   200,											// height
	   3,											// amount of items
	   { TEXT("sin"), TEXT("x^2"), TEXT("ln") },	// name of items
   };

   hwndComboBox = createCB(hWnd, CBSettings);

   EDIT EDITSettings;

   EDITSettings = {
	   125,											// X position
	   15,											// Y position
	   100,											// width text
	   40,											// width field
	   24,											// height
	   TEXT(" Start:"),								// Name
	   ID_EDITBEGINX								// Edit ID
   };

   createEditField(EDITSettings);

   EDITSettings = {
	   260,											// X position
	   15,											// Y position
	   100,											// width text
	   15,											// width field
	   24,											// height
	   TEXT(" Polynom:"),							// Name
	   ID_POLYNOM									// Edit ID
   };

   createEditField(EDITSettings);

   EDITSettings = {
	   370,											// X position
	   15,											// Y position
	   130,											// width text
	   45,											// width field
	   24,											// height
	   TEXT(" Search X:"),							// Name
	   ID_SEARCHX									// Edit ID
   };

   createEditField(EDITSettings);

   CreateWindowW(TEXT("BUTTON"), TEXT("Apply"),
	   WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 510, 15, 50, 24, hWnd, (HMENU)ID_BUTTONAPPLY, hInstance, NULL);

   Array = createSequence();

   TCHAR buf[10];
   SearchX = _wtof(valueFromTextField(ID_SEARCHX, buf));
   Polynom = _wtoi(valueFromTextField(ID_POLYNOM, buf));
   newtonY = newton_method(SearchX, Polynom);
   splinesY = splines_method(SearchX);
   RealY = myFunc()(SearchX);

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}