Solved
Need help with source code; Euler's method
Posted on 1997-04-04
The following is the beginnings of a program which I am currently attempting to write. Its purpose is to do an numerical approzimation for a linear first order differential equation using euler's method. It needs a lot of work. The problem is mainly that it only goes through one step of the analysis. Of course there may be several more problems. If anyone has an idea on how to get it to work, I would appreciate a response.
// Program -- Euleran's
// Uses Euler's meathod to approximate the solution of the differential
// equation y'=f(x,y) for a given interval.
//header files
#include <math.h>
#include <iostream.h>
#include <iomanip.h>
float euler (float);
float x,y,f,equation,h;
int n;
void main()
{
cout.setf(ios::fixed, ios::floatfield); //set up floating point
cout.setf(ios::showpoint); // output format
cout << "Enter the initial value for x: " << endl;
cin >> x;
cout << "Enter the initial value for y: " << endl;
cin >> y;
cout << "Enter the final value for x: " << endl;
cin >> f;
cout << "Enter the number of steps for which you wish the " << endl
<< "function to be analyzed: " << endl;
cin >> n;
cout << "Enter the first order differential equation which you " << endl;
cout << "wish to analyze:" << endl;
cin >> equation;
h=(f-x)/n;
euler (equation);
cout << x << " " << y << endl;
}
float euler (float equation)
{
for(int i=1;i<=n;i++);
{
y=y+h*equation;
x=x+h;
return x,y;
}
}
Thank you,
Ben Key