File:ODE Exp Imp Euler method.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(SVG file, nominally 1,200 × 900 pixels, file size: 10 KB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description
English: Compares the forward/explicit and backward/implicit Euler methods for the numerical solution of the ODE y'(x)=-200*(y-cos(x))-sin(x), y(0)=1. With the substituton z=y-cos(x), the ODE z'=-200*z, z(0)=0, results. Numerical integration of the second ODE should always result in the constant 0. By the nonlinear substitution in the first ODE, numerical errors are introduced in every step that are magnified by the factor 200. For not too small stepsizes, this results in explosive behavior of the explicit method whereas the implicit method remains close to the exact solution.
Date
Source Own work
Author LutzL


Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following licenses:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
You may select the license of your choice.

Source[edit]

Using a small C program and gnuplot.

exp_imp_euler.c[edit]

/*
implizites und explizites Eulerverfahren für y'(x)=-2000*(y-cos(x))-sin(x)

*/

#include<stdio.h>
#include<math.h>

#define ALPHA 200

double f(double x,double y) {
	return -ALPHA*(y-cos(x))-sin(x);
	}
	
double explicit(double x,double y,double h) {
	return y+h*f(x,y);
}
	
double implicit(double x,double y, double h) {
	/* solve yp=y+h*f(xp,yp) for yp
		explicit solution is
		y=yp-h*f(xp,yp)
		 =(1+2000*h)*yp-2000*h*cos(xp)+h*sin(xp)
	*/
	double xp=x+h;
	
	return (y+h*(ALPHA*cos(xp)-sin(xp)))/(1+ALPHA*h);
}


int main(){
	double x,ye,yi,h;
	
	FILE *fp=fopen("imp_euler.dat","w");
	
	x=0; ye=yi=1; h=1.2e-2;
	
	for(;x<1; x+=h){
		fprintf(fp,"%8.5f\t%8.5f\t%8.5f\t%8.5f\n",x,cos(x),ye,yi);
		ye=explicit(x,ye,h);
		yi=implicit(x,yi,h);
	}
	return 0;
}

gnuplot commands[edit]

set term push
set term svg size 1200,900 fsize 28 linewidth 2

set output "exp_imp_euler.svg"

pl [:] [0:2] 'imp_euler.dat' u 1:3 ti 'explizit' w po pt 3, 'imp_euler.dat' u 1:4 w lin lt 3 lw 3 ti 'implizit'

unset outp
set term pop

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current16:30, 4 July 2010Thumbnail for version as of 16:30, 4 July 20101,200 × 900 (10 KB)LutzL (talk | contribs){{Information |Description={{en|1=Compares the forward/explicit and backward/implicit Euler methods for the numerical solution of the ODE y'(x)=-200*(y-cos(x))-sin(x), y(0)=1. With the substituton z=y-cos(x), the ODE z'=-200*z, z(0)=0, results. Numerica

There are no pages that use this file.

File usage on other wikis

The following other wikis use this file:

Metadata