Issue with Ax=b/null space/particular solution.
10 views (last 30 days)
Show older comments
Attached is my code with comments in areas I think are wrong/need help with so far and the pseudo code I'm trying to create the code from. I highlighted the areas I'm having issues with.
function csolve(A,b)
b = b';
B = [A,b];
[m,n]=size(B);
pivot=[];
free=[1:n-1];
rreform=rref(B);
for i= 1:1:m
for j= 1:1:n
if rreform(i,j) == 1
pivot = [pivot,j];
break;
end
end
end
b = B(: ,n);
A = B(: ,1:n-1);
free(pivot)='';
x = rank(B);
xp = zeros(n-1,1);
pA = pivot;%maybe wrong
tempa = pA\b;
xp(pivot) = tempa;
xs = zeros(n-1,free);
for i = 1:free
tempb = 1 ;%here is wrong probably
xs(pivot,i) = pA\tempb;
end
fprintf('A particular solution is: %d \n',xp);
fprintf('The special solutions are: %d \n',xs);
fprintf('The rank of the coefficient matrix is %d. \n',x);
fprintf('Piviot variables: x%d. \n',pivot);% has multiple outputs, want the
outputs on the same line
fprintf('Free variables: x%d. \n',free);% has multiple outputs, want the outputs
on the same line
end
1 Comment
Geoff Hayes
on 15 Oct 2014
Robert - please either format the above code by highlighting it and pressing the {} Code button, or just attach the m-file to your question using the paperclip button.
A couple of your comments are maybe wrong or here is probably wrong. Please elaborate on why you think this is wrong. Also, it is a good idea to add comments to your code so that the reader knows what the code is supposed to do (it isn't that clear from the function name of csolve).
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!