How can I solve this following problem? (overcome * mark)

1 visualización (últimos 30 días)
PULAK Kumer
PULAK Kumer el 25 de En. de 2021
Comentada: Steven Lord el 25 de En. de 2021
My code is :
%Start
clear all
clc
%Input required values
fprintf('***********************Gauss Jodern Elimination Method*************************\n')
fprintf('***************<strong>Code has been created by Pulak(181201)</strong>***********************\n')
format rational
n=input('How many variables?: ');
A=input('coefficient matrix: ');
for i=1:n
for j=1:n
a(i,j)=A(i,j);
end
end
AB=a;
B=input('Constant matrix: ');
for i=1:n
b(i)=B(i);
end
disp('The given equations in matrix form is or Augmented Matrix:')
AB=[A B]
%checking the ranks
%Finding determinant
dett = det(a);
%Check Elemination
if dett == 0
print('This system unsolvable because det(C) = 0 ')
return
else
if rank(A)==rank(AB)
disp('Unique solution exit')
else
disp('Unique solution doesnot exit')
end
j=1;
for i = 1:n-1
if (i==j)
if (AB(i,j)==0)
for q=1:n-1
if (AB(i+q,j)~=0)
c = AB(i,:);
AB(i,:)= AB(i+q,:);
AB(i+q,:) = c;
break
end
end
end
AB(i,:)= (1/AB(i,j))* AB(i,:);
for k=i+1:n
AB(k,:)=(-AB(k,j)* AB(i,:)) + AB(k,:);
end
end
j=j+1;
end
AB(n,:)= (1/AB(n,n))* AB(n,:);
for j=n:-1:2
for i=j-1:-1:1
AB(i,:)=AB(i,:)-AB(j,:)*(AB(i,j))
end
end
disp('The final Matrix is:')
AB
for s=1:n
x(s)=AB(s,n+1)
end
for i=1:n
ans=x(i);
fprintf('\nThe %d-th solution is x(%d)= %.6f',i,i,ans)
end
fprintf('\n\n')
fprintf('***********************<strong>Code has been created by Pulak(181201)</strong>***********************\n')
end
but in the ouput:
***********************Gauss Jodern Elimination Method*************************
***************Code has been created by Pulak(181201)***********************
How many variables?: 4
coefficient matrix: [1 -0.7 0.3 0.5;-6 8 -1 -4;3 1 4 11;5 -9 -2 4]
Constant matrix: [0.2;5;2;7]
The given equations in matrix form is or Augmented Matrix:
AB =
1 -7/10 3/10 1/2 1/5
-6 8 -1 -4 5
3 1 4 11 2
5 -9 -2 4 7
Unique solution exit
The final Matrix is:
AB =
1 * 0 * 3531/923
0 1 0 * 1091/333
0 * 1 * -2063/324
0 * 0 1 1067/923
The 1-th solution is x(1)= 3.825569
The 2-th solution is x(2)= 3.276273
The 3-th solution is x(3)= -6.367281
The 4-th solution is x(4)= 1.156013
***********************Code has been created by Pulak(181201)***********************
My question is why * is seen instead of 0? And how can I overcome this problem?

Respuesta aceptada

Steven Lord
Steven Lord el 25 de En. de 2021
From the help text for the format function:
format RAT Approximation by ratio of small integers. Numbers
with a large numerator or large denominator are
replaced by *.
Most likely this means those elements are small (but non-zero) numbers that have large denominators.
format rational
x = [1, 1e-10]
x =
1 *
  2 comentarios
PULAK Kumer
PULAK Kumer el 25 de En. de 2021
How can i solve this problem sir?
Steven Lord
Steven Lord el 25 de En. de 2021
Some options:
Replace those small values with 0.
Replace them with close approximations that have small denominators.
Display your data using a different display format.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Elementary Math en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by