solving two symbolic equations simultaneously

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])

 採用された回答

Stephan
Stephan 2019 年 7 月 13 日
編集済み: Stephan 2019 年 7 月 13 日

1 投票

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])

その他の回答 (1 件)

SYED IMTIAZ ALI SHAH
SYED IMTIAZ ALI SHAH 2019 年 7 月 13 日

3 投票

Hi, this may help. Write one extra line after your code
sol.x
sol.y

タグ

質問済み:

2019 年 7 月 13 日

編集済み:

2019 年 7 月 13 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by