MATLAB: Solving two symbolic equations simultaneously

syms solve

Hi !
I will not use matrix to solve this problem; if we have:
x + y = a
x – y =b
We know we can get by hand and paper: x=(a+b)/2 and y=(a-b)/2. How can I get the same resulte by using SOLVE function in Matlab?
Here comes my attempt:
clear all
clc
syms x y a b
eq1=a==x+y;
eq2=b==x-y;
sol=solve([eq1 eq2],[x y])

Best Answer

syms x y a b
eq1=a==x+y;
eq2=b==x-y;
[xsol,ysol]=solve([eq1 eq2],[x y])
sol.x
sol.y
or:
syms x y a b
eq1=a==x+y;
eq2=b==x-y;
[xsol,ysol]=solve([eq1 eq2],[x y])
Related Question