23 views (last 30 days)

Show older comments

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

the answer is

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);

fprintf('the answer is',x(1,:))

end

end

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

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

Start Hunting!