Originally posted by Steve Fahlbusch:
Please post the source code and the exact message you are encountering.
Originally posted by C.R.Muthukumar Muthukumar:
Hello
Please try to treat the program emphasising more on object orientation consisting of a large number of functions.Subsequent to recent compilation the result of the same is indicated as only Solution without the output.
The details are as under
1)function(f(x,y)
2)xo,yo
3)increment h
4)number of y values to be found.n
Using Euler's method the following values will be computed
x1,x2,x3 ...xn,y1,y2,y3...yn
The algorithm is:
1)for i=0 to n-1
2)xi+1=xi+h
3)yi+1=yi+hf(x,y)
4)print xi+1,yi+1
5)next i
6)end
The code:
import java.text.*;
import java.util.*;
import java.lang.Math;
import java.lang.Number;
import javax.swing.*;
import java.awt.event.*;
public class EulerIVP1 extends JFrame implements ActionListener{
int n;
double h;
double x[],y[],f[];
public void EulerIVP1(int n,double ax,double ay,double h)
{
setTitle("Euler");
setLayout(new FlowLayout());
addWindowListener(new WH());
this.n=n;
x = new double[n];
y = new double[n];
f = new double[n];
x[0]= ax;
for (int i=1; i<n+1; i++)
x[i] = x[0] + (double)i * h;
y[0] = ay;
}
public double findf(double x, double y)
{
double f = x*x + y*y;
return f;
}
class WH extends WindowAdapter{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals(displaySolution()));
JFrame frame= new JFrame();
EulerIVP1 eqn;
eqn=new EulerIVP1();
eqn.setBounds(1,1,200,300);
eqn.findSolution();
eqn.displaySolution();
eqn.setVisible(true);
eqn.show();
}
public double findSolution()
{
for(int i=1;i < n+1;i++)
{
f[i] = findf(x[i],y[i]);
y[i+i] = y[i] + h * f[i];
}
return;
}
public double displaySolution()
{
System.out.println("Solution");
for (int i=1;i<n+1;i++)
{
System.out.println("x:"+ x[i] + "y:" +y[i]);
}
return;
}
public static double main(String[] args){
double ax;
double ay;
int n=0;
double h=0.5;
EulerIVP1 eqn=new EulerIVP1();
JFrame frame= new JFrame();
eqn.setBounds(1,1,200,300);
eqn.findSolution();
eqn.displaySolution();
eqn.setVisible(true);
eqn.show();
}
}
Hope to get the solutions with the output for this numerical computations
Thanking You
As Always
C.R.Muthukumar
Originally posted by C.R.Muthukumar Muthukumar:
The same Java Code now given under concrete datas and with slight modification is being brought forward to indicate that success always follow
when the job is done in a plethora of times .
Thanks
As Always
C.R.Muthukumar
![]()
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|