solve a system of equations symbolically

조회 수: 2 (최근 30일)
Mahsa Babaee
Mahsa Babaee 2021년 10월 20일
댓글: Mahsa Babaee 2021년 10월 28일
Hello
I want to solve a system of equations symbolically. But I faced some problems. I was wondering if you could guide me on why MATLAB is incapable of the determination of the Z as a function of a1 and a2? And how can I find Z?
Thanks for your attention in advance.
Here is my code:
clc
clear
syms a3 a2 a1
eqn=[a3-3*a2+10*a1==68,5*a3+6*a2+2*a1==31];
S= solve(eqn);
X=S.a1
X = 
Y=S.a2
Y = 
Z=S.a3
Unrecognized field name "a3".

채택된 답변

Paul
Paul 2021년 10월 20일
It looks like there are two equations with three unknowns for which there are many solutions. So solve() gives the results for two of the variables in terms of the third, which you can set to an arbitray value. In this case, it chose to solve for a1 and a2 in terms of a3. But you can make it solve for any two in terms of the third, for example a2 and a3 in terms of a1
syms a3 a2 a1
eqn = [a3-3*a2+10*a1==68,5*a3+6*a2+2*a1==31];
S = solve(eqn,[a2 a3])
S = struct with fields:
a2: (16*a1)/7 - 103/7 a3: 167/7 - (22*a1)/7
Now pick an arbitrary value for a1, say sqrt(3), and show that the solution satisfies the eqn
subs(eqn,[a1 a2 a3],[sqrt(3) subs([S.a2 S.a3],a1,sqrt(3))])
ans = 
  댓글 수: 3
Paul
Paul 2021년 10월 28일
It seems like you did everything correct. Are you getting results different than shown as follows?
syms S1 S2 S3 A1 A2 A3 B1 B2 B3 M21 M32
eqn=[A1*sinh(S1)+B1*sinh(S1)-B2==0, A2*sinh(S2)+B2*cosh(S2)-B3==0, A3*sinh(S3)+B3*cosh(S3)==0, A1*cosh(S1)+B1*sinh(S1)-A2*M21==0, A2*cosh(S2)+B2*sinh(S2)-A3*M32==0];
S= solve(eqn, [A2 A3 B1 B2 B3]);
S.A2
ans = 
S.A3
ans = 
S.B1
ans = 
S.B2
ans = 
S.B3
ans = 
Mahsa Babaee
Mahsa Babaee 2021년 10월 28일
Thanks a million.
It works!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by