write a program to find a root of non linear equation using Muller's method.
Source Code:
/********************************************
program: solution of non-linear equation
bisection method
language: C
Author : Tanveer Khan
Rajasthan University, Jaipur
************************************************/
#include<iostream.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(pow(x,3)+2*pow(x,2)+10*x-20);
}
void main()
{
clrscr();
float h,x4,x1,x2,x3,d1,d2,h1,h2,a0,a1,a2;
int i,n;
cout<<"MULLER METHOD\n";
cout<<"enter no. of iterations ";
cin>>n;
cout<<"enter 3 root values : ";
cin>>x1>>x2>>x3;
for(i=1;i<=n;i++)
{
h1=x1-x3;
h2=x2-x3;
d1=f(x1)-f(x3);
d2=f(x2)-f(x3);
a0=f(x3);
a1=(d2*(h1*h1)-d1*(h2*h2))/(h1*h2*(h1-h2));
a2=(d1*h2-d2*h1)/(h1*h2*(h1-h2));
if(a1<=0)
{
h=(-2*a0)/(a1-sqrt(pow(a1,2)-4*a2*a0));
}
else
{
h=(-2*a0)/(a1+sqrt(pow(a1,2)-4*a2*a0));
}
x4=x3+h;
cout<<"iteration"<<i<<":\nx1="<<x1<<"\tx2="<<x2<<"\tx3="<<x3;
cout<<"\nh1="<<h1<<"\th2="<<h2<<"\td1="<<d1<<"\td2="<<d2<<"\n";
cout<<"a0="<<a0<<"\ta1="<<a1<<"\ta2="<<a2<<"\th="<<h<<"\tx4="<<x4<<endl<<endl;
x1=x2;
x2=x3;
x3=x4;
}
getch();
}
OUTPUT:
Comments
Post a Comment