Numerical Integration

Trapezoidal

#include<stdio .h>
#include<conio .h>
#include<math .h>
#define f(x) pow(x,3)+1

void main()
{
	int j;
	float n,a,b,h,i,i1,i2=0;
	clrscr();
	printf("Enter a and b::");
	scanf("%f%f",&a,&b);
	printf("enter the value of n");
	scanf("%f",&n);
	h=(b-a)/n;
	printf("%f",h);
	i1=f(a)+f(b);
	for(j=1; j<n ; j++)
	{
		i2+=f(a+j*h);
	}
	i=(i1+2*i2)*h/2;
	printf("nnI=%f",i);
	getch();
}

Simson’s 1 by 3

#include<stdio .h>
#include<conio .h>
#include<math .h>
#define f(x) pow(x,3)+1

void main()
{
	int j;
	float a,b,n,h,i,i1,i2=0,i3=0;
	clrscr();
	printf("Enter a and b::");
	scanf("%f%f",&a,&b);
	printf("enter the value of n");
	scanf("%f",&n);
	h=(b-a)/n;
	i1=f(a)+f(b);
	for(j=1; j<n ; j++)
	{
		if (j%2==0) i2+=f(a+j*h);
		else i3+=f(a+j*h);
	}
	i=(i1+4*i3+2*i2)*h/3;
	printf("nnI=%f",i);
	getch();
}

Simpson’s 3 by 8

#include<stdio .h>
#include<conio .h>
#include<math .h>
#define f(x) pow(x,-1)

void main()
{
	int j;
	float a,b,n,h,i,i1,i2=0,i3=0;
	clrscr();
	printf("Enter a and b::");
	scanf("%f%f",&a,&b);
	printf("enter the value of n");
	scanf("%f",&n);
	h=(b-a)/n;
	i1=f(a)+f(b);
	for(j=1; j<n ; j++)
	{
		if (j%3==0) i2+=f(a+j*h);
		else i3+=f(a+j*h);
	}
	i=(i1+3*i3+2*i2)*(3*h)/8;
	printf("nnI=%f",i);
	getch();
}

Least Square Regression

y=ax+b

#include <stdio .h>
#include <conio .h>


void main()
{
	clrscr();
	float x[10],y[10],x2=0, x1y1=0, y1=0, x1=0;
	int i,n;
	printf("Enter the number of data::");
	scanf("%d",&n);
	printf("nnEnter the data::");
	for(i=0; i<n ; i++)
	{
		printf("nnx[i]=");
		scanf("%f",&x[i]);
		printf("ty[i]=");
		scanf("%f",&y[i]);
	}
	for(i=0; i<n; i++)
	{
		x2+=(x[i]*x[i]);
		x1y1+=(x[i]*y[i]);
		y1+=y[i];
		x1+=x[i];
	}
	float b=(n*x1y1-x1*y1)/(n*x2-(x1*x1));
	float a=(y1-b*x1)/n;
	printf("nna=%fttb=%f",a,b);
	getch();
}

y=axb

#include <stdio .h>
#include <conio .h>
#include<math .h>


void main()
{
	clrscr();
	float x[10],y[10],x2=0, x1y1=0, y1=0, x1=0;
	int i,n;
	printf("Enter the number of data::");
	scanf("%d",&n);
	printf("nnEnter the data::");
	for(i=0; i<n ; i++)
	{
		printf("nnx[i]=");
		scanf("%f",&x[i]);
		x[i]=log(x[i]);
		printf("ty[i]=");
		scanf("%f",&y[i]);
		y[i]=log(y[i]);
	}
	for(i=0; i<n; i++)
	{
		x2+=(x[i]*x[i]);
		x1y1+=(x[i]*y[i]);
		y1+=y[i];
		x1+=x[i];
	}
	float b=(n*x1y1-x1*y1)/(n*x2-(x1*x1));
	float a=(y1-b*x1)/n;
	a=exp (a);
	printf("nna=%fttb=%f",a,b);
	getch();
}

Divided Difference

#include<stdio .h>
#include<conio .h>
#include<math .h>

void main()
{
	float x[10],f[10][10],a[10],x0,sum=0;
	int n,i,j,d;
	printf("No. of data");
	scanf("%d",&n);
	for(i=0;i<n ;i++) {
		printf("x=");
		scanf("%f",&x[i]);
		printf("f(x)=");
		scanf("%f",&f[i][0]);
	}
	printf("Enter the value of x for which f(x) is to be determined");
	scanf("%f",&x0);

	for(j=1;j<n;j++)
	{
		for(i=0;i<n;i++)
		{
			f[i][j]=(f[i+1][j-1]-f[i][j-1])/(x[i+j]-x[i]);
		}
	}
	for(j=0;j<n;j++)
		a[j]=f[0][j];
	sum=a[0];
	for(i=1;i<n;i++)
	{
	d=1;
	for(j=0;j<i;j++)
		d*=(x0-x[j]);
	sum+=a[i]*d;
	}
	printf("%f",sum);
	getch();
}

Lagrange Interpolation

#include<stdio .h>
#include<conio .h>
#include<math .h>

void main()
{
	float x[10],fx[10],l,x0,p=0;
	int n,i,j;
	printf("No. of data");
	scanf("%d",&n);
	for(i=0;i<n ;i++) {
		printf("x=");
		scanf("%f",&x[i]);
		printf("f(x)=");
		scanf("%f",&fx[i]);
	}
	printf("Enter the value of x for which f(x) is to be determined");
	scanf("%f",&x0);
	for(i=0;i<n;i++)
	{
		l=1;
		for(j=0;j<n;j++)
			if(j!=i)	l*=(x0-x[j])/(x[i]-x[j]);
		p+=l*fx[i];
	}
	printf("P=%f",p);
	getch();
}

Complex roots using Horner’s Rule(N-R Method)

#include<stdio .h>
#include<conio .h>
#include<math .h>

struct complex {
	float r,i;
};

struct complex add(struct complex a,struct complex b) {
	struct complex temp;
	temp.r=a.r+b.r;
	temp.i=a.i+b.i;
	return temp;
}
struct complex sub(struct complex a,struct complex b) {
	struct complex temp;
	temp.r=a.r-b.r;
	temp.i=a.i-b.i;
	return temp;
}
struct complex mul(struct complex a,struct complex b) {
	struct complex temp;
	temp.r=a.r*b.r-a.i*b.i;
	temp.i=a.r*b.i+a.i*b.r;
	return temp;
}
struct complex div(struct complex a,struct complex b) {
	struct complex temp;
	temp.r=(a.r*b.r+a.i*b.i)/(b.r*b.r+b.i*b.i);
	temp.i=(a.i*b.r-a.r*b.i)/(b.r*b.r+b.i*b.i);
	return temp;
}
float cabs(struct complex a) {
	return sqrt(a.r*a.r+a.i*a.i);
}

void main()
{
	struct complex a[10],b[10],c[10],x1,x2,e;
	int n,j;
	clrscr();
	printf("Enter the degree of the polynomial:");
	scanf("%d",&n);
	printf("Enter the coefficents:");
	for(j=0;j< =n;j++)
		scanf("%f%f",&a[j].r,&a[j].i);
	printf("Enter initial guess:");
	scanf("%f%f",&x1.r,&x1.i);
	printf("The roots are:n");
	b[0]=a[0];c[0]=a[0];
	do{
		do{
			for(j=1;j<=n;j++)
				b[j]=add(a[j],mul(b[j-1],x1));
			for(j=1;<n;j++)
				c[j]=add(b[j],mul(c[j-1],x1));
			x2=sub(x1,div(b[n],c[n-1]));
			e=div(sub(x2,x1),x2);
			x1=x2;
		} while(cabs(e)>0.0001);
		printf("%.3f+%.3fin",x1.r,x1.i);
		for(j=1;<n ;j++)
			a[j]=b[j];
		n--;
	} while(n!=0);
	getch();
}

Roots using Newton-Raphson and Secant Method

Newton-Raphson Method

#include<stdio .h>
#include<conio .h>
#include<math .h>
#define f(x) pow(x,3)-4*x+1
#define d(x) 3*pow(x,2)-4
#define er 0.001
void main()
{
	clrscr();
	float e,x1,x2,fx1,dx1;
	int i=1;
	printf("Initial Guess x1::");
	scanf("%f",&x1);
	printf("Iterationt x1t f(x1)t f'(x1)t x2t |(x2-x1)/x1|n");
	do{
		fx1=f(x1);
		dx1=d(x1);
		x2=x1-(fx1/dx1);
		e=fabs((x2-x1)/x2);
		printf("%dtt%6.3ft%6.3ft%6.3ft%6.3ft%6.3fn",i,x1,fx1,dx1,x2,e);
		x1=x2;
		i++;
	}while(e>er);

	printf("nThe root : %f",x1);
	getch();
}

Secant Method

#include<stdio .h>
#include<conio .h>
#include<math .h>
#define f(x) pow(x,3)-3*pow(x,2)+x+1
#define er 0.001
void main()
{
	clrscr();
	float e,x1,x2,x3,fx1,fx2;
	int i=1;
	printf("Initial Guesses x1 and x2::");
	scanf("%f%f",&x1,&x2);
	printf("Iterationt x1t x2t x3t fx1t fx2n");
	do{
		fx1=f(x1);
		fx2=f(x2);
		x3=x2-((x2-x1)*fx2/(fx2-fx1));
		e=fabs(x3-x2)/x3;
		x1=x2;
		x2=x3;
		printf("%dtt%6.3ft%6.3ft%6.3ft%6.3ft%6.3fn",i,x1,x2,x3,fx1,fx2);
		i++;
	}while(e>er);

	printf("nThe root : %f",x3);
	getch();
}

8085 Simulator

After a brief search for a good 8085 simulator, I ended up with GNUSim8085

Very easy to use and pretty impressive look and feel.

Okay, now for installation.

If you are using a debian distro, the author congrats you coz’ it’s available in the repo. Just fire up a terminal and sudo aptitude install gnusim8085

There you go. GNUSim8085 is installed in your machine.

Now for windows. It’s not as easy as typing a line into your terminal but not that difficult though.

Download the latest version of GTK+ for Windows Runtime Environment from http://sourceforge.net/projects/gtk-win/

Let’s complete the downloads part first.

Download the program GNUSim8085 from

http://www.gnusim8085.org

The download link’s on the right side of the page. The file name is gnusim8085-x.x.x-no-gtk-installer.exe

All downloads done!!!

Now, let’s carry on with the installation process.

Install the runtime-environment first.

After its sucessful installation, start installing GNUSim8085

If all goes well you will be able to use the simulator. The author provides you with some tutorial on using the sim and also some example programs.

Roots Using Bisection Method

#include<stdio .h>
#include<conio .h>
#include<math .h>
#define f(x) pow(x,3)-4*x-9
#define e 0.001
void main()
{
	clrscr();
	float x0,x1,x2,fx0,fx1,fx2;
	int i=1;
	do{
		printf("Initial Guesses x1 &amp;amp; x2::");
		scanf("%f %f",&x1,&x2);
		fx1=f(x1);
		fx2=f(x2);
	}while(fx1*fx2>0);
	printf("Iterationt x1t x2t x0t f(x1)t f(x2)t f(x0)n");
	do {
		x0=(x1+x2)/2;
		fx0=f(x0);
		fx1=f(x1);
		fx2=f(x2);
		printf("%dtt%.3ft%.3ft%.3ft%6.3ft%6.3ft%6.3fn",i,x1,x2,x0,fx1,fx2,fx0);
		if(fx1*fx0<0) x2=x0;
		else x1=x0;
		i++;
	} while((fabs(x2-x1)/x2)>e);
	printf("nThe root : %f",x0);
	getch();
}

TwiSkip HomePage

I always loved the “Skip Inbox” function in GMail and so much wanted it in twitter as well.
Here’s the same function for the twitter and I love calling it “Twiskip”

Ever wanted to get the tweets from a tweeterholic but didn’t want your homepage overcrowded with their tweets?

Here’s a simple solution.

Just go to their profile page and add them to one of your lists[Note:don’t follow]

If you are already following the person.Just unfollow them and add them to the list.

Simple as it is!!!

🙂