「java拟合曲线」如何计算拟合曲线
今天给各位分享java拟合曲线的知识,其中也会对如何计算拟合曲线进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、java如何用描点法绘制双曲线
- 2、谁能给一个java编写的利用最小二乘法进行曲线拟合的算法?
- 3、java画双曲线
- 4、如何用java做数据曲线图
- 5、java可以拟合曲线吗
- 6、基于java图形类实现函数曲线的绘制
java如何用描点法绘制双曲线
一个点一个点的画是最简单的。然后用Path2D来画直线。
Path2D.Double path = new Path2D.Double () ;
for (int i = 0 ; i 100; i ++)
{
double y = f (x) ;
path.lineTo(x, y) ;
// 这里可以用quadTo () ;但要提供差值点。
}
Graphics2D g2 = (Graphics2D) g ;
g.draw (path) ;
补充:quadTo可能就是差值算法,这样你可以减少采样点来达到平滑曲线的效果。另外就是用RanderHint来进行抗锯齿等平滑处理。
谁能给一个java编写的利用最小二乘法进行曲线拟合的算法?
最小二乘发拟合的是直线吧,不是曲线,非线性曲线拟合你的有模型,知道曲线的方程式。或者就是差值了,三次样条或者B样条。
java画双曲线
public class Test3 {
public static void main(String[] args) {
TriFunc tri = new TriFunc();
// 生成一块25×100的画布
Canvas canvas = new Canvas(25, 100);
// 画sin曲线,周期为2
tri.drawSin(canvas, 2.0);
canvas.printCanvas();
System.out.println();
canvas.reset();
// 画cos曲线,周期为2
tri.drawCos(canvas, 2.0);
canvas.printCanvas();
}
}
class TriFunc {
/**
* 画sin曲线
* @param canvas 画布
* @param period 曲线周期
*/
public void drawSin(Canvas canvas, double period) {
char[][] chars = canvas.getCanvas();
// x 轴的比率
double xRatio = (2 * period * Math.PI) / (canvas.getWidth() - 1);
// y 轴的放大倍率
int yMulti = (canvas.getHeight() - 1) / 2;
for(int i = 0; i canvas.getWidth(); i++) {
// 将数组索引映射为横坐标值
double k = (i - canvas.getWidth() / 2) * xRatio;
// 将sin值映射为数组索引
int h = yMulti - (int)Math.round(Math.sin(k) * yMulti);
chars[h][i] = Canvas.FILL_CHAR;
}
}
/**
* 画cos曲线
* @param canvas 画布
* @param period 曲线周期
*/
public void drawCos(Canvas canvas, double period) {
char[][] chars = canvas.getCanvas();
double xRatio = (2 * period * Math.PI) / (canvas.getWidth() - 1);
int yMulti = (canvas.getHeight() - 1) / 2;
for(int i = 0; i canvas.getWidth(); i++) {
double k = (i - canvas.getWidth() / 2) * xRatio;
int h = yMulti - (int)Math.round(Math.cos(k) * yMulti);
chars[h][i] = Canvas.FILL_CHAR;
}
}
}
class Canvas {
private int height;
private int width;
private char[][] canvas;
// 填充字符
public static char FILL_CHAR = '#';
// 空白字符
public static char BLANK_CHAR = ' ';
/**
* 构建一块画布
* @param height
* @param width
*/
public Canvas(int height, int width) {
// 由于需要画坐标轴,所以得采用奇数
this.height = height % 2 == 0 ? height + 1 : height;
this.width = width % 2 == 0 ? width + 1 : width;
init();
}
/**
* 初始化画布
*/
private void init() {
this.canvas = new char[height][width];
for(int i = 0; i height; i++) {
for(int j = 0; j width; j++) {
canvas[i][j] = BLANK_CHAR;
}
}
addAxis();
}
/**
* 添加坐标轴
*/
private void addAxis() {
// 添加横坐标
int y = height / 2;
for(int x = 0; x width; x++) {
canvas[y][x] = '-';
}
// 添加纵坐标
int xx = width / 2;
for(int yy = 0; yy height; yy++) {
canvas[yy][xx] = '|';
}
// 添加原点
canvas[y][xx] = '+';
}
/**
* 输出画布
*/
public void printCanvas() {
for(int i = 0; i height; i++) {
for(int j = 0; j width; j++) {
System.out.print(canvas[i][j]);
}
System.out.println();
}
}
/**
* 清空画布
*/
public void reset() {
init();
}
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
public char[][] getCanvas() {
return canvas;
}
}
来自CSDN 楼主可以去看看。。。。我是蜗牛。。。嘿嘿
如何用java做数据曲线图
首先使用JXL读取excel的数据 然后使用JFreeChart把数据转成曲线图 说明: jxl.jar是通过java操作excel表格的工具类库支持Excel 95-2000的所有版本 JFreeChart是JAVA平台上的一个开放的图表绘制类库. 效果图
java可以拟合曲线吗
Java当然可以,只要能够方便的进行图形显示的语言都可以做这项工作。
Python之类的语言有相应的库,可以更方便的处理。
基于java图形类实现函数曲线的绘制
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import com.bruceeckel.swing.*;// 这个包你要自己去下,此处无法上传,整个程序你还要修改一下,以满足f(x)=x^2+sin(x)在区间[-3,3]的函数图像
class SineDraw extends JPanel {
static final int SCALEFACTOR = 200;
int cycles;
int points;
double[] sines;
int[] pts;
SineDraw() { setCycles(5); }
public void setCycles(int newCycles) {
cycles = newCycles;
points = SCALEFACTOR * cycles * 2;
sines = new double[points];
pts = new int[points];
for(int i = 0; i points; i++) {
double radians = (Math.PI/SCALEFACTOR) * i;
sines[i] = Math.sin(radians);
}
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
int maxWidth = getWidth();
double hstep = (double)maxWidth/(double)points;
int maxHeight = getHeight();
for(int i = 0; i points; i++)
pts[i] = (int)(sines[i] * maxHeight/2 * .95
+ maxHeight/2);
g.setColor(Color.red);
for(int i = 1; i points; i++) {
int x1 = (int)((i - 1) * hstep);
int x2 = (int)(i * hstep);
int y1 = pts[i-1];
int y2 = pts[i];
g.drawLine(x1, y1, x2, y2);
}
}
}
public class SineWave extends JApplet {
SineDraw sines = new SineDraw();
JSlider cycles = new JSlider(1, 30, 5);
public void init() {
Container cp = getContentPane();
cp.add(sines);
cycles.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent e) {
System.out.println( ((JSlider)e.getSource()).getValue());
sines.setCycles( ((JSlider)e.getSource()).getValue());
}
});
cp.add(BorderLayout.SOUTH, cycles);
}
public static void main(String[] args) {
Console.run(new SineWave(), 700, 400);
}
} ///:~
关于java拟合曲线和如何计算拟合曲线的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。