Wednesday, November 12, 2014

Matlab Program for finding positive root of a Non-Linear Function using Regula-Falsi Method

k=input('Enter the function =  ', 's');
f= inline(k);
a=0; b=1;
for i=1:inf
    if f(a)*f(b)<0
        break
    else
        a=a+1;
        b=b+1;
    end
end
for i=2:inf
   x(i)= (a*f(b)-b*f(a))/(f(b)-f(a));
   if f(x(i))*f(a)<0
       b=x(i);
   else
       a=x(i);
   end
   if abs(x(i)-x(i-1))<=0
      Iteration=i-1
      Root=x(i)
      break
   end
end

Tuesday, November 4, 2014

Matlab Program for finding positive root of a Non-Linear Function using Newton Rapson Method

a=input('Enter the function =  ', 's');
f= inline(a);
h= diff(a);
d= inline(h);
x(1)=0;
for k=1:inf
    if f(x(1))>0
      for i=2:inf
      x(i)= x(i-1)-((f(x(i-1)))/(d(x(i-1))));
       if abs(x(i)-x(i-1))<=0.001 && x(i)>0  
       Root=x(i)
       break 
       end
       end
       break
     else
      x(1)=x(1)+1;
    end
end

Monday, November 3, 2014

Matlab Program for finding positive root of a Non-Linear Funtion using Secant Method

a=input('Enter the function =  ', 's');
f= inline(a);
x(1)=0; x(2)=1;iteration=0;
for k=1:inf
 if f(x(1))*f(x(2))<0
  for i=3:inf
  x(i)=(x(i-2)*(f(x(i-1)))-x(i-1)*(f(x(i-2))))/(f(x(i-1))-f(x(i-2)));
  iteration=iteration+1;
    if abs(x(i)-x(i-1))<=0.001 && x(i)>0
    root=x(i)
    iteration=iteration
    break
    end
  end
  break
 else
 x(1)=x(1)+1;
 x(2)=x(2)+1;
 end
end


Wednesday, October 22, 2014

Matlab Program for Solving Non-Linear Equation using Bisection Method

a=input('Enter the function =  ', 's');
f= inline(a);
a=0; b=1;x=0;
for i=1:inf
    if f(a)*f(b)<0
        break
    else
        a=a-i; % replace - by + to get positive root
        b=b+i;
    end
end
for i=2:inf
   x(i)= (a+b)/2;
   if f(x(i))*f(a)<0
       b=x(i);
   else
       a=x(i);
   end
   if abs(x(i)-x(i-1))<=0.0001
       break;
   end
end
Iteration=i
Root=x(i)

Monday, October 20, 2014

Matlab Program for 3 Variables simultaneous equations using Gauss Seidel Method

a = input('Enter the Augmented Matrix >  ')
x(1)=0; y(1)=0; z(1)=0;
for i=2:100
    x(i)=( a(10) - a(4)*y(i-1) - a(7)*z(i-1) )/a(1);
    y(i)=( a(11) - a(2)*x(i-1) - a(8)*z(i-1) )/a(5);
    z(i)=( a(12) - a(3)*x(i-1) - a(6)*y(i-1) )/a(9);
    e1=abs(x(i)-x(i-1));
    e2=abs(y(i)-y(i-1));
    e3=abs(z(i)-z(i-1));
    if e1<=0.001 && e2<=0.001 && e3<=0.001
        Iteration=i
        x = x(i)
        y = y(i)
        z = z(i)
        break
    end
end

Matlab Program for 3 Variables simultaneous equations using Jacobi Iteration Method

a = input('Enter the Augmented Matrix >  ')
x(1)=0; y(1)=0; z(1)=0;
for i=2:100
    x(i)=( a(10) - a(4)*y(i-1) - a(7)*z(i-1) )/a(1);
    y(i)=( a(11) - a(2)*x(i-1) - a(8)*z(i-1) )/a(5);
    z(i)=( a(12) - a(3)*x(i-1) - a(6)*y(i-1) )/a(9);
    e1=abs(x(i)-x(i-1));
    e2=abs(y(i)-y(i-1));
    e3=abs(z(i)-z(i-1));
    if e1<=0.001 && e2<=0.001 && e3<=0.001
        Iteration=i
        x = x(i)
        y = y(i)
        z = z(i)
        break
    end
end