simple_euler - float x[NSTEP+1], y[NSTEP+1]; for (i = 0; i...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* simple_euler.c * Simple Euler's method solution of dy/dx=y with y(0)=1, from x=0 to x=1. */ #include <stdio.h> #define NSTEP 10 /* number of integration steps */ #define XMIN 0.0 /* starting point for integration */ #define XMAX 1.0 /* stopping point for integration */ #define Y0 1.0 /* initial value */ int main() { int i; float h = (XMAX - XMIN)/NSTEP; /* stepsize for integration */
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: float x[NSTEP+1], y[NSTEP+1]; for (i = 0; i <= NSTEP; i++) /* Define array of x values */ x[i] = XMIN + h * i; y[0] = Y0; /* initial value */ printf("%f %f\n", x[0], y[0]); for (i = 0; i < NSTEP; i++) { y[i+1] = y[i] + h*y[i]; /* do one integration step */ printf("%f %f\n", x[i+1], y[i+1]); } return 0; }...
View Full Document

This note was uploaded on 09/29/2009 for the course COSC 1002 taught by Professor Wheatland during the Three '09 term at University of Sydney.

Ask a homework question - tutors are online