简体   繁体   English

在Java中找到坡度的截距

[英]find intercept from slope in java

i want to find intercept of a series of value,since i have found the slope is there any way to find intercept value from slope or any other way to find intercept, this is my code,: 我想找到一系列值的截距,因为我已经找到了斜率,所以有什么方法可以从斜率中找到截距值,或者是否有其他方法可以找到截距,这是我的代码:

        double[] x_values = { 120,180,240 };
         double[] y_values = { l1,l2,l3};

                 if (x_values.length == y_values.length)
                 {
                 for (int i = 0; i < (x_values.length - 1); i++) {
                    double y_2 = y_values[i + 1];
                    double y_1 = y_values[i];

                    double delta_y = y_2 - y_1;

                    double x_2 = x_values[i + 1];
                    double x_1 = x_values[i];

                    double delta_x = x_2 - x_1;

                    slope += delta_y / delta_x;
                }
                 }
              double slope_val= slope / (x_values.length-1);

Fundamentally a line can be defined by two points. 从根本上说,一条线可以由两个点定义。 So if you're going to be finding the slope of a line, you can use two points to calculate it. 因此,如果要查找直线的斜率,则可以使用两个点进行计算。

If you have more than two points, then you could use a more sophisticated extrapolation method. 如果您有两个以上的点,则可以使用更复杂的外推方法。 Two reasons for this: One, if your points aren't exactly co-linear than your algorithm is essentially just taking the average of the slope between consecutive point pairs. 造成这种情况的原因有两个:一,如果您的点与算法不完全共线性,则实际上只是取连续点对之间的斜率平均值。 Two, even if you're points ARE co-linear there will probably be some numerical issues in the arithmetic that cause it to pretty much default to the first case. 第二,即使您的观点是共线性的,在算术中也可能会出现一些数值问题,导致其在默认情况下几乎是第一种情况。 However, if you are in the second case then what you have is probably fine and you don't need to overcomplicate it. 但是,如果您处于第二种情况,那么您所拥有的可能就很好了,并且不需要过于复杂。

Back directly to your question, you are finding the average slope between consecutive points. 直接回到您的问题,您正在找到连续点之间的平均斜率。 To find the intercept you're going to want to plug that slope into y=mx + b with one of your given points to find the b part of the equation. 要找到截距,您将要使用给定的点之一将该斜率插入y=mx + b ,以找到等式的b部分。 After that you're set to find the x-intercept or the y-intercept by setting either y=0 or x=0 , respectively, and solving. 之后,您可以通过分别设置y=0x=0并求解来设置x截距或y截距。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM