ارجو المساعدة بسرعة


(lara303) #1

solve numerical equation like gauss method by mat lab here is the equation
3x1-.1x2-.2x3=7.85
.1x+7x2-.3x3=-19.3
.3x1-.2x2+10x3=71.4
please help me as soon as possible


(mr.volt) #2

[LEFT][SIZE=3]اليك الكود مع النتائج

%Linear equation system 'Ax=r' by Gauss elimination method.

clc
clear all
%=================================================================
disp('Solution of N-equation "[A][X]=[r]"')
n=input ('Enter number of Equations :');
A=input ('Enter Matrix [A]:');
r=input ('Enter Matrix [r]:'); 
D=A;d=r;
%-----------------------------------------------------------------
%create upper triangular matrix 
s=0;
for j=1:n-1 
    if A(j,j)==0
        k=j;
        for k=k+1:n
            if A(k,j)==0
                continue 
            end
            break
        end
        B=A(j,:); C=r(j); 
        A(j,:)=A(k,:); r(j)=r(k);
        A(k,:)=B; r(k)=C;
    end
    for i=1+s:n-1
        L=A(i+1,j)/A(j,j);
        A(i+1,:)=A(i+1,:)-L*A(j,:);
        r(i+1)=r(i+1)-L*r(j);
    end
    s=s+1;
end 
%-----------------------------------------------------------------
%Solution of equations
x(n)=r(n)/A(n,n);
for i=n-1:-1:1
    sum=0;
    for j=i+1:n 
        sum=sum+A(i,j)*x(j);
    end
    x(i)=(1/A(i,i))*(r(i)-sum);
end
%------------------------------
%Checking with matlab functions
p=inv(D)*d;
%------------------------------
%Output
disp('@----------------------------------------------------------@')
disp('Output [B][x]=[b]')
disp('Upper riangular Matrix [B] =');disp(A)
disp('Matrix [b] =');disp(r)
disp('solution of linear equations :');disp(x')
disp('solve with matlab functions(for checking):');disp(p) 









بعد تنفيذ البرنامج قم بادخال ما يطلب منك وستظهر لك النتائج تباعا :

Solution of N-equation "[A][X]=[r]"
Enter number of Equations :3
Enter Matrix [A]:[3 -0.1 -0.2 ; 0.1 7 -0.3 ; 0.3 -0.2 10 ]
Enter Matrix [r]:[7.85 -19.3 71.4]'
@----------------------------------------------------------@
Output [B][x]=[b]
Upper riangular Matrix [B] =
    3.0000   -0.1000   -0.2000
         0    7.0033   -0.2933
         0         0   10.0120

Matrix [b] =
    7.8500
  -19.5617
   70.0843

solution of linear equations :
    3.0000
   -2.5000
    7.0000

solve with matlab functions(for checking):
    3.0000
   -2.5000
    7.0000

[/size][/left]