Obsidian
The Dork Knight
- Joined
- Sep 16, 2002
- Messages
- 12,795
- Reaction score
- 0
- Points
- 31
I was wondering if someone could help me with this program I'm working on. It's focusing on interpolation (for those that don't know what that means, it means that you're taking a set of points and creating a new set of data points}. I've got the input down, I'm just not sure how to program the method.
/**
* @(#)Interpolation.java
*
* Interpolation application
*
* @author
* @version 1.00 2007/5/5
*/
import java.io.*;
import java.lang.Double;
public class Interpolation {
public static void main(String[] args)throws Exception {
int N; // the number of points to be interpolated
int mew; // the number of x points to be inputed
double[] xinter; // the x-values of the interpolated points
double[] yinter; // the y-values of the interpolated points
double[] newx; // the new x-values inputed
double[] newy; // the new y-values outputed
String input = "";
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
double[] lfct; // the L function
double[] yfct; // the Y function
double[] pfct; // the Lagrange polynomial value
System.out.println("Please enter the number of points to be interpolated");
input = in.readLine();
N = Integer.parseInt(input);
xinter = new double[N];
yinter = new double[N];
int sub = 0;
for (int i = 1; i <= N; i++){
System.out.println("Please enter x " + i);
input = in.readLine();
xinter[sub] = Double.parseDouble(input);
System.out.println("Please enter y " + i);
input = in.readLine();
yinter[sub] = Double.parseDouble(input);
sub++;
}
System.out.println("Please enter the number of x-values");
input = in.readLine();
mew = Integer.parseInt(input);
newx = new double[mew];
for (int j = 0; j < mew; j++){
System.out.println("Please enter the x(s):");
input = in.readLine();
newx[j]= Double.parseDouble(input);
}
}
}
I'm going to use Lagrange formula, but I can't for the life of me figure out how to code it. I understand the method pretty well, but when it gets down to coding, I'm lost. I have a general idea that it's going to involve a few loops, but yeah, if anyone can help me ASAP, it would be appreciated.
that's the general equation where the Yj refers to the Y coordinates that are going to be entered. The Xj will be used in the l(x) part of the equation, l(x) is the only part I'm really worried about. Once I get that, I'll be fine with the rest.
If you don't understand it, I'm welcome to explaining it.
Cheers,
Obsidian
/**
* @(#)Interpolation.java
*
* Interpolation application
*
* @author
* @version 1.00 2007/5/5
*/
import java.io.*;
import java.lang.Double;
public class Interpolation {
public static void main(String[] args)throws Exception {
int N; // the number of points to be interpolated
int mew; // the number of x points to be inputed
double[] xinter; // the x-values of the interpolated points
double[] yinter; // the y-values of the interpolated points
double[] newx; // the new x-values inputed
double[] newy; // the new y-values outputed
String input = "";
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
double[] lfct; // the L function
double[] yfct; // the Y function
double[] pfct; // the Lagrange polynomial value
System.out.println("Please enter the number of points to be interpolated");
input = in.readLine();
N = Integer.parseInt(input);
xinter = new double[N];
yinter = new double[N];
int sub = 0;
for (int i = 1; i <= N; i++){
System.out.println("Please enter x " + i);
input = in.readLine();
xinter[sub] = Double.parseDouble(input);
System.out.println("Please enter y " + i);
input = in.readLine();
yinter[sub] = Double.parseDouble(input);
sub++;
}
System.out.println("Please enter the number of x-values");
input = in.readLine();
mew = Integer.parseInt(input);
newx = new double[mew];
for (int j = 0; j < mew; j++){
System.out.println("Please enter the x(s):");
input = in.readLine();
newx[j]= Double.parseDouble(input);
}
}
}
I'm going to use Lagrange formula, but I can't for the life of me figure out how to code it. I understand the method pretty well, but when it gets down to coding, I'm lost. I have a general idea that it's going to involve a few loops, but yeah, if anyone can help me ASAP, it would be appreciated.
that's the general equation where the Yj refers to the Y coordinates that are going to be entered. The Xj will be used in the l(x) part of the equation, l(x) is the only part I'm really worried about. Once I get that, I'll be fine with the rest.
If you don't understand it, I'm welcome to explaining it.
Cheers,
Obsidian