Friday 14 October 2016

Coding the Regula Falsi

The convergce process in the bisection method is very slow. It depends only on the choice of end points of the interval [a,b]. The function f(x) does not have any role in finding the point c (which is just  the mid-point of a and b). It is used only to decide the next smaller interval [a,c] or [c,b]. A better approximation to c can be obtained by taking the straight line L joining the points (a,f(a)) and (b,f(b)) intersecting the x-axis. To obtain the value of c we can equate the two expressions of the slope m of the line L.






Let's take an Equation   :-  x*x*x-17




#include<stdio.h>
 struct iter
 {
     float x1;
     float x0;
 };
 float f(float x)
 {

    float y;
    y=x*x*x-17;

    return y;
 }
 float f1(float x)
 {
     float y1;
      y1=3*x*x;
      return y1;
 }

 void main()
 {
     int n,i;
     float a,b,x0,x1,x2,x3,x4,x5,x6;

     printf("enter the intervals");
     scanf("%f%f" ,&a,&b);
     printf("\nEnter the number of iterations\n");
     scanf("%d",&n);
     if(f(a)*f(b)<0)
     {
         printf("root is possible between interval %f %f " ,a,b);

     }
     else
     {

    printf("root does not lie between %f %f \n" ,a,b);
    exit(1);

     }

 if(fabs(f(a))<fabs(f(b)))
 x0=f(a);

 else

 x0=f(b);
 x0=a;

 printf("xnot is %f \n " ,x0 );
struct iter k[1000];
 k[0].x0=x0;
i=0;
while(n!=0)
{

  k[i].x1=k[i].x0-(f(k[i].x0)/f1(k[i].x0));

 printf("\n%f" ,k[i].x1);
 k[i+1].x0= k[i].x1;

--n;
++i;

}


 }




Tuesday 4 October 2016

multi threading in JAVA



Java is a multi-threaded programming language which means we can develop multi-threaded program using Java. A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.
By definition, multitasking is when multiple processes share common processing resources such as a CPU. Multi-threading extends the idea of multitasking into applications where you can subdivide specific operations within a single application into individual threads. Each of the threads can run in parallel. The OS divides processing time not only among different applications, but also among each thread within an application.
Multi-threading enables you to write in a way where multiple activities can proceed concurrently in the same program.


A thread is a basic process that can be made run individually!!

class main
{
public static void main(String args[])
{
A ob =new A();
ob.start();
}
}
class A extends Thread   // creating a thread

{
public void run()

{
System.out.println(" A thread is running ");
}
}