Sunday, November 3, 2019

False position method or Regular falsi method

False position method or Regular falsi method

Code is Here

//false position method or regular falsi method
clear;clc;close
deff('y=f(x)','y=x^2.2-69');
printf("The given function is y=x^2.2-69 \n\n");
a=input("Enter first approximation : ");
b=input("Enter second approximation : ");
d=input("Enter accuracy : ");
printf('succesive iterations    \ta\t    b\t    f(a)\t    f(b)\t\  x1\n');
for i=1:25
    x1=b*f(a)/(f(a)-f(b))+a*f(b)/(f(b)-f(a));
    if(f(a)*f(x1))>0
        b=x1;
    else
        a=x1;
    end
    if abs(f(x1))<d
        break
    end
    printf('                         \t%f  %f  %f  %f  %f\n',a,b,f(a),f(b),x1);
end
printf('the root of the equation is  %f',x1);



False position method or Regular falsi method
Add False position method or Regular falsi method

Simpson's three by eight rule

Simpson's three by eight rule


Code is Here

clear;clc
fxn=input("Enter the fuction : (eg:y=(x^2+5*x+6)) : ")
deff('y=f(x)',fxn);
printf("The given function is %s\n\n",fxn);
a=input('Inter the lower limit : ')
b=input('Inter the upper limit : ')
n=input('Inter the value of n : ')
h=(b-a)/n
for i=0:n
    X(1,i+1)=a+h*i
    Y(1,i+1)=f(a+h*i)
end
printf("x=")
disp(X)
printf("y=")
disp(Y)
a1=Y(1,1)+Y(1,n+1);
a2=0
for j=3:3:n-1
    a2=a2+Y(1,j+1);
end
a3=0
for k=0:n-1
    p=modulo(k,3)
if p==0
else
    a3=a3+Y(1,k+1);
end
end
i=(3*h/8)*(a1+2*a2+3*a3);
printf("The value of Integral is : ")
disp(i)



Simpson's three by eight rule
Simpson's three by eight rule