0
votes

i'm trying to use 'solve' method to solve equations in matlab , i have a matrix which Coefficients of the variables are in it called 'A'

but when i use solve method with this code (i want A(1,1) to be the Coefficients for x variable) :

W0 = solve('A(1,1)*x+13*y-16*z=1','13*x-10*y+13*z=0','-16*x+13*y-7*z=0')
W0 = [W0.x W0.y W0.z]

i dont get the correct answer and it shows me this for answer:

[ 11/(11*A(1, 1) + 185), 13/(11*A(1, 1) + 185), -1/(11*A(1, 1) + 185)]

meaning the Value of A(1,1) is not recognized in code, can anyone help me getting right answer?

3

3 Answers

2
votes

How about

W0 = solve([num2str(A(1,1)),'*x+13*y-16*z=1'],'13*x-10*y+13*z=0','-16*x+13*y-7*z=0')
2
votes

Using solve,

W0 = solve(strcat(num2str(A(1,1)), '*x+13*y-16*z=1'),'13*x-10*y+13*z=0','-16*x+13*y-7*z=0');
W0 = [W0.x W0.y W0.z]
1
votes

Avoid solve, and use \ instead.

W0 = ([A(1,1) 13 -16; 13 -10 13; -16 13 -7]\[1;0;0])'