solve a equation in matlab with variable

224 views Asked by At

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

There are 3 answers

1
Dan On BEST ANSWER

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')
0
user1543042 On

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]
2
user1543042 On

Avoid solve, and use \ instead.

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