Search: | |||||

| ||||

Home » Forum » Java | RSS Feeds |

What i need is to draw a X-Y graph and a line across the X-Y, a slope

accoring to a 20 points. the line should pass the points that create

this line, The least-square.

and they are y=mx+b

where m=(the sum of the products of the corresponding x and y values)-

(the sum of the x values)*(the average of y values)/(the sum of the

square of x values)-(the sum of the x values)*(the average of the x

values)

Also,

b is the slope, which is definde as b=( the average of y values)-m*

(the average of the x values)

I have found the m and i used this an dit did work

public class SquaresFit

{

public static void main(String[] args)

{

double [] a = { -4.91 , -3.84 , -2.41 , -2.62 ,-3.78 , -0.52 , -

1.83 , -2.01 , 0.28 , 1.08 , - 0.94 , 0.59 , 0.69 , 3.04 ,

1.01 , 3.6 , 4.53 , 5.13 , 4.43 , 4.12 };

// Insert values to array

double [] b = { -8.18 , -7.49 , -7.11 , -6.15 , -5.62 , -3.3 , -

2.05 , -2.83 , -1.16 , 0.52 , 0.21 , 1.73 , 3.96 , 4.26 ,

5.75 ,6.67 , 7.7 , 7.31 , 9.05 , 10.5 };

double sum_x = 0;

double sum_y = 0; // Declared variables

double sqr_x = 0;

double sum_xy = 0;

double m;

int i;

for ( i=0 ; i<=19 ; i++) // Loop to find sum of x&y , x*y

and square of x.

{

sum_x += a[i]; // sum_x = sum_x + a[i];

sum_y += b

[i]; // .

sum_xy += a[i] * b

[i]; // .

sqr_x += a[i] * a

[i]; // .

}

System.out.println("The sum of X : "

+ sum_x);

System.out.println("The sum of Y : "

+ sum_y); // Print values of elements.

System.out.println("The sum of Square X : "

+ sqr_x);

System.out.println("The sum of X*Y : "

+sum_xy);

double avg_x = sum_x /5 ; // To

find the average of X & Y.

double avg_y = sum_y /5 ;

System.out.println("The average of

X : " + avg_x);

System.out.println("The

average of Y : " + avg_y); // Print the averages.

m = (sum_xy - (sum_x * avg_y)) / (sqr_x -

(sum_x * avg_x)); // Culculate the last operation

// to test the method.

System.out.println("The result : "+ m); // the

result is = 1.818

}

So, what i need now is to find the "y" and the "b", which i will try

it. But, how can i use the APPLETS in this methods ? and how woudl i

draw the graph?

what classes i shoudl use, if you coudl give me hints, i would be

pleased.

If you still need a answer then let me know.

Didn't find what you were looking for?
Find more on draw a X-Y graph and a line across the X-Y, a slope accoring to a 20 points
Or get search suggestion and latest updates.

Related Topics:

- Moving my C# project from XP to another computer running Windows 20
- 20 Mins Process in Application Server
- getting the sum of the last 20 cells
- to find slope
- C++ Write a program which takes as input 4 points and tell whether these points
- 2-line title on a xy line plot
- Write a line in a new line
- Problem invoking ejbs across servers
- Best way to load multiple images across multiple classes in an appl
- Sharing Excel Across the Network
- Graph equation
- plotting graph in applet
- Graph,Edge,Node classes
- Common header across all my aspx files
- Java-based NoSQL Graph Database
- Tx propagation across multiple weblogic servers
- Hibernate mapping across multiple databases
- Graph program does not work with data from Access via MS Query
- Naming series in multiple Graphs
- dynamic graph title
- Graphs Help Needed
- Help on CEWolf graphs
- Time difference calculations across midnight
- Write assembly program that check 20 numbersstored in the data segment if it is odd or even
- graph visit