# Diagonal matrix, wishing to solve Ax=b

23 views (last 30 days)
Chandler Shimp on 26 Jan 2020
Commented: Abel Medina on 6 Mar 2021
I am not getting any errors, but I am certainly doing something wrong.
I wish to get output that is the result of x for x=b/A
where A is an nxn matrix
b a vector
I am trying to create function called solveDiag(A,b)
instead of getting desired output i get the original matrix A
so my output is:
"ans =
2
ans= [3 0 0
0 2 0
0 0 7]"
This what I have:
function [A,b]=solveDiag(A,b)
%A=nxn diagonal matrix
%b=column vector
%n is number of unknowns in matrix
A=[3 0 0 ; 0 2 0 ; 0 0 7];
b=[4 8 21]
for i = 1, 2,...,n do
x(1,:)=b(i)/A(i,i);
end
end
Chandler Shimp on 27 Jan 2020
Thank you all very much, we have managed to create a function that delivers desired output!
Ignore the first line in command, i first used () to declare c instead of []. Les Beckham on 26 Jan 2020
I thought that I had commented on this question earlier with something that should work for you. Here is the code that I think should work for you.
A = diag([3 2 7])
b = [4 8 21];
b/A
Abel Medina on 6 Mar 2021
lol