scientific computing - Solve linear system of equations with free variables MATLAB -


this 3*5 matrix , there 2 free variables. don't know if best way solve in matlab. doesn't work , output empty sym: 0-by-1

clear x_1 x_2 x_3 x_4 x_5 syms x_1 x_2 x_3 x_4 x_5  eqn1 = x_1+0*x_2+3*x_3+2*x_4-4*x_5==4 ; eqn2 = 2*x_1+x_2+6*x_3+5*x_4+0*x_5==7 ; eqn3 = -x_1+x_2-3*x_3-x_4+x_5==-5 ;  tic ;  res = solve([eqn1,eqn2,eqn3]) ;  toc ; 

you don't need symbolic math toolbox simple system of linear equations. you're better off using mldivide, common enough has shorthand \.

for system ax = b, x vector of x values, a matrix of coefficients, , b product (right hand side of system), can solve

x = a\b; 

so

a = [1  0  3  2 -4;       2  1  6  5  0;      -1  1 -3 -1  1];  b = [4; 7; -5];  x = a\b >> ans = [0; 0; 2; -1; 0]; 

you can manually check result (x3=2, x4=-1, x1=x2=x5=0) works.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -