Write a program to demonstrate Milne Simpson Method in C language.

Tested on: Turbo C++ Version 4.0Time Complexity: O (n*k)Where k is inner collection of iterationsSpace Complexity: O (1)Open Source: MIT
1
2
3
        /*Program to execute Milne Simpson Method*/
4
	#include <stdio.h>
5
	#include <conio.h>
6
	#include <math.h>
7
	float dif(float x, float y)
8
	{
9
	    return x + y;
10
	}
11
	float pred(float y0, float h, float f1, float f2, float f3)
12
	{
13
	    return y0 + 4 * h * (2 * f1 - f2 + 2 * f3) / 3;
14
	}
15
	float corr(float y2, float h, float f2, float f3, float f4)
16
	{
17
	    return y2 + h * (f2 + 4 * f3 + f4) / 3;
18
	}
19
	void main()
20
	{
21
	    float x, h, x0, x1, y0, y1, y2, y3, y4, x4, f1, f2, f3, f4;
22
	    float aerr, yc, yc1;
23
	    printf("Enter the values of x, h, x0, aerr: ");
24
	    scanf("%f%f%f%f", &x, &h, &x0, &aerr);
25
	    printf("Enter the values of y0, y1, y2, y3: ");
26
	    scanf("%f%f%f%f", &y0, &y1, &y2, &y3);
27
	    while (x4 < x)
28
	    {
29
	        f1 = dif(x0 + h, y1);
30
	        f2 = dif(x0 + 2 * h, y2);
31
	        f3 = dif(x0 + 3 * h, y3);
32
	        printf("\n\nf1=%f\tf2=%f\tf3=%f\n", f1, f2, f3);
33
	        y4 = pred(y0, h, f1, f2, f3);
34
	        x4 = x0 + 4 * h;
35
	        f4 = dif(x4, y4);
36
	        printf("\nPredicator values:");
37
	        printf("\n\ty=%f\tf4=%f", y4, f4);
38
	        y4 = corr(y2, h, f2, f3, f4);
39
	        f4 = dif(x4, y4);
40
	        printf("\nCorrector values:");
41
	        printf("\n\ty=%f\tf4=%f", y4, f4);
42
	        yc = corr(y2, h, f2, f3, f4);
43
	        f4 = dif(x4, yc);
44
	        printf("\n\ty=%f\tf4=%f", yc, f4);
45
	        while (fabs(yc - y4) > aerr)
46
	        {
47
	            y4 = yc;
48
	            yc = corr(y2, h, f2, f3, f4);
49
	            f4 = dif(x4, yc);
50
	            printf("/n/ty=%f\tf4=%f", yc, f4);
51
	        }
52
	        x0 += h;
53
	        printf("\nValues of y=%f, when x=%f", yc, x4);
54
	        y0 = y1;
55
	        y1 = y2;
56
	        y2 = y3;
57
	        y3 = y4;
58
	    }
59
	    getch();
60
	}
61
            
62
         

Output

1
2
            
3
        Enter the values of x, h, x0, aerr: 0.3 0.05 0 0.0001
4
	Enter the values of y0, y1, y2, y3: 1 1.0525 1.1103 1.1736
5
	
6
	f1 = 1.102500         f2 = 1.210300       f3 = 1.323600
7
	Predictor Values:
8
	    y = 1.242793      f4 = 1.442793
9
	Corrector Values:
10
	    y = 1.242758      f4 = 1.442758
11
	    y = 1.242758      f4 = 1.442758
12
	Value of y = 1.242758, when x = 0.200000
13
	
14
	f1 = 1.210300         f2 = 1.323600        f3 = 1.442758
15
	Predictor Values:
16
	    y = 1.318001      f4 = 1.568001
17
	Corrector Values:
18
	    y = 1.317977      f4 = 1.567977
19
	    y = 1.317977      f4 = 1.567977
20
	Value of y = 1.317977, when x = 0.250000
21
	
22
	f1 = 1.323600         f2 = 1.442758       f3 = 1.567977
23
	Predictor Values:
24
	    y = 1.3399660      f4 = 1.699660
25
	Corrector Values:
26
	    y = 1.399664      f4 = 1.699664
27
	    y = 1.399664      f4 = 1.699664
28
	Value of y = 1.399664, when x = 0.300000
29
        
30
        

Rate the Code

Reviews are published after a quick safety check (usually within 24 hours).

Reviews are public. Developers can see basic device specifications to respond. Learn more

How to run Milne Simpson Method program in C-Language?

To run Milne Simpson Method program in C-Language, follow the below mentioned steps:

  1. Copy the Code: Press the copy button in the code block to copy the complete code.
  2. Open Turbo C++ Version 4: Open the Turbo C++ (Version 4) software on your system.
  3. Paste the code: Paste the copied code into Turbo C++’s editor.
  4. Compile the Code: Compile the program by pressing the Alt+F9 keys. This shows you the errors and warnings, if any.
  5. Run the code: Press the Ctrl+F9 keys to run the program if the program is successfully compiled.
  6. Enter the Input: Provide the required inputs or your desired inputs, if applicable.
  7. Receive the Result: Get the result of the program on the screen based on the provided inputs.

More about the Milne-Simpson Method

Discovered By: British Mathematician and Astrophysicist Edward Arthur Milne

Discovered Year: 20th Century

Local Truncation Error: O(h5)

Method Type: 4th-Order Predictor-Corrector Method

This is also known as Milne’s Method. This is a multi-step predictor-corrector method to solve ordinary differential equations (ODEs).

How does the Milne Simpson Method work?

  1. Predictor formula: This method finds a rough value based on the last 4 points (yn-3, yn-2, yn-1, yn)
  2. Corrector Formula: With the help of the rough value, it calculates the correct value by checking the slope of the last 4 points.

Why is the Milne-Simpson method used?

Unlike single-step methods like the Runge-Kutta 4th Order Method that re-evaluate the function multiple times per step from scratch, Milne-Simpson is a multi-step method that reuses past calculated points, making each step computationally faster.

Real-life applications of the Milne-Simpson Method

  1. Aerospace and Long-Term Orbital Calculations: To track the trajectory for satellites and spacecraft over months or days.
  2. Continuous system Simulations: Used in simulations where the data continually changes with respect to time and old data is also known.

Limitations of Milne Simpson Method

  1. First 4 points should be known: To start this method, at least 4 starting points should be known; else we have to use the Runge-Kutta 4th Order Method.
  2. Stability Problem: If the step size (h) is large, then there is a high chance of error accumulating due to instability in that step.

Alternate Methods

  1. Adams-Bashforth-Moulton Method: This method solves the stability problem for the steps.
  2. Hamming’s Modified Predictor: If the chances of instability are very high for big data, then Hamming’s Modified Predictor is used instead of the Milne-Simpson Method.
License: This program's source code is open-sourced under the MIT License, while the rest of the program's text content and overall dhimanp platform and brand content remain proprietary under dhimanp.

Submit your modified code

Your submissions are published after a quick safety check (usually within 7 days).

Submissions are public. Developers can see basic device specifications to respond. Learn more

Disclaimer

The information that you shared with us will be publicly visible, and everyone can see your information. And we (dhimanp) are not responsible if anyone misuses this information. We can remove any submitted code at any time for better transparency.

Privacy Policy

If you share your data with us by submitting your code for credit, then we may show your full name, school or college name, and city name on our website.

We are not using this data to track you and are not selling this data to anyone.

If you want to remove your name from our website, you can contact us, and we will remove your name from our website. In the removal process, full credit, including your full name, school or college, city, and code, will be removed from our website.