Hello,
I created a gauss elimination with partial pivoting and back substitution to solve a system of linear equations. What I am having trouble with is creating a matrix that has an element defined as a variable that is updated for a given range of numbers in order to produce a number of solutions based on the range and increments provided. I recieve the following error message:"Error using vertcat: Dimensions of arrays being concatenated are not consistent."
Thank you for your help.
function [x] = FwdElimPPivBckSub(A,b)ticR3 = (30.1:.1:100);A = [1 -1 -1 0 0; 0 0 1 -1 -1; 30 0 0 -25 -25; -25 0 R3 0 -6; 0 0 -6 0 21;];b = [0; 0; 110; 0; -45];n = length(b);for k = 1:n-1 p = k; big = abs(A(k,k)); for ii = k+1:n dummy = abs(A(ii,k)); if dummy > big p = ii; end end if p ~= k for jj = k:n dummy = A(p,jj); A(p,jj)= A(k,jj); A(k,jj)= dummy; end dummy = b(p); b(p) = b(k); b(k) = dummy; end for i = k+1:n factor = A(i,k)/A(k,k); for j = k+1:n A(i,j) = A(i,j)-factor *A(k,j); end b(i) = b(i) - factor*b(k); endendfor i = 1:nx(i) = b(i)/A(i,i);endfor i = n-1:-1:1 sum = b(i); for j = i+1:n sum = sum - A(i,j)*x(j); end x(i) = sum/A(i,i);endtoc
Best Answer