📄 interpolate.java
字号:
/** * file: interpolate.java * *last edited: Ryan Irwin *///class imports//import java.awt.*;import java.util.*;import javax.swing.*;import java.lang.* ;/** * Interpolate class * */public class interpolate{ // public members double m , c; Vector<MyPoint> iset = new Vector<MyPoint>(40, 20); // pulic methods /** * Interpolates * * @param v input vector * @return output vector */ public Vector<MyPoint> interpol(Vector<MyPoint> v) { // dummy variables for internal use // // size = size of the input data set // p, q, r, t = dummmy points // int size, l = 0; double a, sample, d, temp ; // MyPoint p, q, t; MyPoint r = new MyPoint(); MyPoint p = new MyPoint(); MyPoint q = new MyPoint(); MyPoint t = new MyPoint(); // the size of the data points // size = v.size(); p =(MyPoint)v.lastElement(); q =(MyPoint)v.firstElement(); // do not know, but the code works with this...? // display the input data points // for checking purpose // // System.out.println("input data points "+ v); /* if(p.x < 0 && q.x < 0) d = Math.abs(q.x) - Math.abs(p.x); else if (p.x > 0 && q.x > 0) d = Math.abs(p.x) - Math.abs(q.x); else d = Math.abs(p.x) + Math.abs(q.x);*/ iset.removeAllElements(); // total time interval of the data points calculated // d = p.x - q.x; // check purpose, displaying the time interval // // System.out.println("total time interval = " + d); // time step calculation // sample = MathUtil.SetDecimal(d/(size-1), 2) ; // Check up of the values calculated // time step and first new point // // System.out.println(" Time Step = " + sample); // System.out.println( // " First New Point is the First (USER-Given) data point! "); // System.out.println(" First New Point > " + q.x); // iset holds new data points - interpolated values // First value added // iset.addElement(new MyPoint(q) ); // Next New Time value calculated and displayed temp = q.x ; r.x = sample + temp; MathUtil.SetDecimal(r.x, 2); // System.out.println(" First New Point > " + q.x); // System.out.println( // "Time T_ONE @ which amplitude is to be calculated " + r.x); while (r.x <= p.x) { for(int j = 1; j < v.size(); j++) { t = ( MyPoint) v.elementAt(j); // the New Interpolated amplitude will be calculated // for the two points within which the time intervals // lies, Hence, the condition check // if ((r.x <= t.x) && (r.x >= ((MyPoint)v.elementAt(j-1)).x)) { slope((MyPoint)v.elementAt(j-1),t); // System.out.println( // "slope = " + m + " y_intercept = ," + c); // amplitude calculation r.y = 0.0 ; r.y = MathUtil.SetDecimal(( m * r.x + c), 2) ; // MathUtil.SetDecimal(r.y, 2); // System.out.println( // "Time Instant (x-value) > " + r.x); // System.out.println( // "Amplitude (y-value) > " + r.y); // New value appended to the array // iset.addElement(new MyPoint(r)); // System.out.println( // "The Interpolated values till now " + iset); // System.out.println("hi" + r.x + "," + r.y); l++; // mypoint and store in vector break; } } // q.x = 0.0; // q.y = 0.0; // q.x = r.x ; // q.y = r.y; r.x = r.x + sample; MathUtil.SetDecimal(r.x, 2); } iset.addElement(new MyPoint(p)); // System.out.println("input data points " + iset); return iset ; } /** * Sets the slope variable m and c * * @param u Point one * @param v Point two */ public void slope(MyPoint u , MyPoint v) { // double m , c ; // System.out.println(" v.y > " + v.y + "v.x > " + v.x); // System.out.println(" u.y > " + u.y + "u.x > " + u.x); m = (v.y - u.y)/(v.x-u.x) ; c = u.y - m*u.x ; MathUtil.SetDecimal(m,2); MathUtil.SetDecimal(c,2); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -