MATLAB Answers


Solving a system of equations without "syms"

Asked by Daniel Miller on 11 Oct 2019
Latest activity Commented on by Daniel Miller on 11 Oct 2019
I have been given the following system of equations that I should solve:
2x1 + 4x2 + 7x3 = 64
3x1 + x2 + 8x3 = 71
-2x = -4
Now, the problem is that I'm on the MatLab Grader platform and it doesn't seem to have this Symbolic Math Tool (i.e. "syms") in it. It only returns the error "Undefined function 'syms' for input arguments of type 'char'."
My code looks like this:
syms x1 x2 x3
equation1 = 2*x1 + 4*x2 + 7*x3 == 64;
equation2 = 2*x1 + 1*x2 + 8*x3 == 71;
equation3 = -2*x1 == -4;
solutionX = solve([equation1, equation2, equation3], [x1, x2, x3]);
SolutionX1 = solution.x1
SolutionX2 = solution.x2
SolutionX3 = solution.x3
Is there any other method I could use instead of using "syms"?
Thank you in advance!


Sign in to comment.


2 Answers

Answer by jeewan atwal on 11 Oct 2019
 Accepted Answer

A*x = b;
for your case
A = [2 4 7; 2 1 8; -2 0 0];
b = [64;71;-4];
where x = [x1;x2;x3]
solution x can be found using either of two methods as follows:
x = inv(A)*b;
x = linsolve(A,b)


Show 1 older comment
DON'T use inv. I know that may be how you were told to solve a linear system in school. In theory, that may be fine. In practice, use the backslash operator (\) instead.
If you have any doubt, you are free to ask. Happy to help.
Thankyou Steven Lord for the info.
Alright, thanks for the additional heads-up. Don't know how I would've solved this without your help so big appreciations for it!

Sign in to comment.

Answer by Stephan
on 11 Oct 2019
Edited by Stephan
on 11 Oct 2019

  1 Comment

Hello and thank you for the advice as well!

Sign in to comment.