30

30

Ahmed
  1. LANGRANGE’S INTERPOLATION

n=input('Enter the no of Elements= ');

for (i=1:n)

x(i)=input('Enter the Value of X= ');

y(i)=input('Enter the Value of Y= ');

end

xg=input('Enter the value of xg=');

yg=0;

for(j=1:n)

num=1;

den=1;

for(i=1:n)

if(i~=j)

num=num*(xg-x(i));

den=den*(x(j)-x(i));

end

end

l(j)=num/den;

yg=yg+l(j)*y(j);

end

fprintf(' Final Value of yg= %f',yg);


2. INVERSE INTERPOLATION

n=input('Enter the no of Elements= ');

for (i=1:n)

x(i)=input('Enter the Value of X= ');

y(i)=input('Enter the Value of Y= ');

end

yg=input('Enter the value of yg=');

xg=0;

for(j=1:n)

num=1;

den=1;

for(i=1:n)

if(i~=j)

num=num*(yg-y(i));

den=den*(y(j)-y(i));

end

end

l(j)=num/den;

xg=xg+l(j)*x(j);

end

fprintf(' Final Value of xg= %f',xg);


3. GAUSS ELIMINATION

n=input('Enter the no. of variables=');

for i=1:n

for j=1:1:n

fprintf('\n a(%d)(%d)=',i,j);

a(i,j)=input('');

end

fprintf('\n c(%d)=',i);

c(i)=input('');

end

for i=1:1:n-1

for k=i+1:1:n

if abs(a(k,i))>abs(a(i,j))

for j=1:1:n

temp=a(i,j);

a(i,j)=a(k,j);

a(k,j)=temp;

end

temp=c(i);

c(i)=c(k);

c(k)=temp;

end

end

end

for i=1:1:n-1

for k=i+1:1:n

temp=a(k,i)/a(i,i);

for j=1:1:n

a(k,j)=a(k,j)-temp*a(i,j);

end

c(k)=c(k)-temp*c(i);

end

end

for i=n:-1:1

temp=c(i);

for j=i+1:1:n

temp=temp-a(i,j)*x(j);

end

x(i)=temp/a(i,i);

end

for i= 1:1:n

fprintf ('the value of x=%f',x(i));

end


4. GAUSS SEIDAL METHOD

fx=inline('(16-y-2*z)/4');

fy=inline('(10-x-z)/3');

fz=inline('(12-x-2*y)/5');

n=input('Enter the no of iterations= ');

x=0;

y=0;

z=0;

for i=1:n

x=fx(y,z);

y=fy(x,z);

z=fz(x,y);

end

fprintf('The values of x y z =%f %f %f',x,y,z);


5. THOMAS ALGORITHM

n=input('Enter no of equation:');

for (i=1:1:n)

if(i==1)

b(i)=input('\nEnter b:');

c(i)=input('\nEnter c:');

elseif(i==n)

a(i)=input('\nEnter a:');

b(i)=input('\nEnter b:');

else

a(i)=input('\nEnter a:');

b(i)=input('\nEnter b:');

c(i)=input('\nEnter c:');

end

d(i)=input('\nEnter d:');

end

for(i=2:1:n)

m=a(i)/b(i-1);

b(i)=b(i)-m*c(i-1);

d(i)=d(i)-m*d(i-1);

end

x(n)=d(n)/b(n);

for (i=n-1:-1:1)

x(i)=(d(i)-c(i)*x(i+1))/b(i);

end

for(i=1:1:n)

fprintf('\nValue of x is:%f',x(i));

end

Report Page