euler Algorithm

The Euler Algorithm, also commonly known as Euler's method, is a first-order numerical technique used to solve ordinary differential equations (ODEs) with a given initial value. Named after Swiss mathematician Leonhard Euler, the algorithm is based on the idea of using tangent lines to approximate the curve described by the differential equation. Euler's method is simple and easy to implement but may lack accuracy compared to other more advanced numerical methods. However, despite its limitations, it remains a vital starting point for understanding the basics of numerical methods in solving ODEs. The algorithm involves dividing a given interval into small subintervals, then iteratively approximating the solution of the differential equation at each subinterval. To begin, the initial point is provided, and the tangent line is computed using the given ODE. The tangent line's slope is then used to estimate the solution's value at the next subinterval. This process is repeated for each subinterval, thus generating an approximate solution for the entire interval. While the Euler Algorithm may not yield highly accurate results for complex or stiff differential equations, it serves as the foundation for understanding more sophisticated numerical methods like the Runge-Kutta method or the multistep method, which provide better accuracy and stability.
#include <stdio.h>
#include <stdbool.h>
#include "Graph.h"

// Return the number of vertices that v is 
// connected to
int degree(Graph g, int nV, Vertex v) {
   int deg = 0;
   Vertex w;
   for (w = 0; w < nV; w++)
      if (adjacent(g, v, w))
	 deg++;
   return deg;
}

// If start from vertex v, decide if the 
// graph has euler path
bool hasEulerPath(Graph g, int nV, Vertex v, Vertex w) {
   if (v != w) {
      if (degree(g, nV, v) % 2 == 0 || degree(g, nV, w) % 2 == 0)
	      return false;
   } else if (degree(g, nV, v) % 2 != 0) {
      return false;
   }
   Vertex x;
   for (x = 0; x < nV; x++)
      if (x != v && x != w && degree(g, nV, x) % 2 != 0)
	 return false;
   return true;
}

int main(void) {
   Edge e;
   int n;

   printf("Enter the number of vertices: ");
   scanf("%d", &n);
   Graph g = newGraph(n);

   Vertex src, dest;
   printf("Enter source node: ");
   scanf("%d", &src);
   printf("Enter destination node: ");
   scanf("%d", &dest);
   
   printf("Enter an edge (from): ");
   while (scanf("%d", &e.v) == 1) {
      printf("Enter an edge (to): ");
      scanf("%d", &e.w);
      insertEdge(g, e);
      printf("Enter an edge (from): ");
   }
   printf("Finished.\n");

   printf("The graph has ");
   if (hasEulerPath(g, n, src, dest))
      printf("an");
   else
      printf("no");
   printf(" Euler path from %d to %d.\n", src, dest);

   freeGraph(g);
   return 0;
}



// By 
//  .----------------.  .----------------.  .----------------.  .-----------------.  .----------------.  .----------------. 
// | .--------------. || .--------------. || .--------------. || .--------------. | | .--------------. || .--------------. |
// | |  _________   | || | _____  _____ | || |      __      | || | ____  _____  | | | |  ____  ____  | || |     ____     | |
// | | |  _   _  |  | || ||_   _||_   _|| || |     /  \     | || ||_   \|_   _| | | | | |_   ||   _| | || |   .'    `.   | |
// | | |_/ | | \_|  | || |  | |    | |  | || |    / /\ \    | || |  |   \ | |   | | | |   | |__| |   | || |  /  .--.  \  | |
// | |     | |      | || |  | '    ' |  | || |   / ____ \   | || |  | |\ \| |   | | | |   |  __  |   | || |  | |    | |  | |
// | |    _| |_     | || |   \ `--' /   | || | _/ /    \ \_ | || | _| |_\   |_  | | | |  _| |  | |_  | || |  \  `--'  /  | |
// | |   |_____|    | || |    `.__.'    | || ||____|  |____|| || ||_____|\____| | | | | |____||____| | || |   `.____.'   | |
// | |              | || |              | || |              | || |              | | | |              | || |              | |
// | '--------------' || '--------------' || '--------------' || '--------------' | | '--------------' || '--------------' |
//  '----------------'  '----------------'  '----------------'  '----------------'   '----------------'  '----------------' 
 
//  Email :    z5261243@unsw.edu.au
//             hhoanhtuann@gmail.com

LANGUAGE:

DARK MODE: