Hello!
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!

 採用された回答

jeewan atwal
jeewan atwal 2019 年 10 月 11 日

2 投票

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;
or
x = linsolve(A,b)

4 件のコメント

Daniel Miller
Daniel Miller 2019 年 10 月 11 日
編集済み: Daniel Miller 2019 年 10 月 11 日
Hey and thank you for the reply! I'm still fairly new with Matlab so it's not very easy for me to understand, but this seems familiar to me.
So first, I got the three values by writing:
A = [2 4 7; 2 1 8; -2 0 0];
b = [64;71;-4];
x1 = linsolve(A,b)
But now, I should store these values in a column vector. I want the vector to be called x. How should I do this? I tried the following:
A = [2 4 7; 2 1 8; -2 0 0];
b = [64;71;-4];
x1 = linsolve(A,b);
x = [x1]
Does this mean that the solutions of linsolve are now stored in the column vector "x"?
EDIT: I managed to solve this, it was correct! Once again, thank you so much for the help!
Steven Lord
Steven Lord 2019 年 10 月 11 日
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.
jeewan atwal
jeewan atwal 2019 年 10 月 11 日
If you have any doubt, you are free to ask. Happy to help.
Thankyou Steven Lord for the info.
Daniel Miller
Daniel Miller 2019 年 10 月 11 日
Alright, thanks for the additional heads-up. Don't know how I would've solved this without your help so big appreciations for it!

サインインしてコメントする。

その他の回答 (2 件)

Stephan
Stephan 2019 年 10 月 11 日
編集済み: Stephan 2019 年 10 月 11 日

0 投票

1 件のコメント

Daniel Miller
Daniel Miller 2019 年 10 月 11 日
Hello and thank you for the advice as well!

サインインしてコメントする。

GAGANDEEP KAUR
GAGANDEEP KAUR 2020 年 11 月 2 日

0 投票

I also need to determine some variables using syms with solve command but find some issue with syms itself.
Code is like this:
for i=1:9
syms a b c d e ;
%calculating mole fractions of ionic species
x1=[0.5096 0.5092 0.5087 0.4852 0.4847 0.4834 0.4804 0.4805 0.4803];
x2=[0.0963 0.0964 0.0965 0.1163 0.1161 0.1158 0.1275 0.1266 0.1253];
x3=[0.3941 0.3944 0.3948 0.3985 0.3992 0.4008 0.3921 0.3929 0.3943];
T=[394.15 399.15 404.15 375.15 390.15 405.15 374.15 392.15 406.15];
%Equilibrium constant for reaction 1 (Solvation reaction)
K1=exp((-8.549)+(6692/T(i)));
%Equilibrium constant for reaction 2(Ionization of water)
K2=10^(-14);
%Equilibrium constant for reaction 3(Dissociation of HI)
K3=exp((16.93565)+((1250)/T(i))+(-2.575*log(T(i))));
%Equilibrium constant for reaction 4(Polyiodide formation a)
K4=exp((-936.28)+((40216.27)/T(i))+(151.983*(log(T(i))))+(-0.1675*(T(i))));
%Equilibrium constant for reaction 5(Polyiodide formation b)
K5=exp((1044.78)+(-45171.42/T(i))+(-165.20*log(T(i)))+(0.1511*(T(i))));
eqns=[((d*(c-e))/((x1(i)-a-b-c-d)^5)*(x2(i)-d-b-c))==K1,((a+b+c)*a)/((x1(i)-a-b-c-d)^2)==K2,(((a+b+c)*(d+b))/((x1(i)-a-b-c-d)*(x2(i)-d-b-c-e)))==K3,(((a+b+c)*(c-e))/((x1(i)-a-b-c-d)^4*(x2(i)-d-b-c-e)))==K4,(((e)*(x1(i)-a-b-c-d)^3)/((c-e)*(x3(i)-e)))==K5];
S=solve(eqns,a, b, c, d, e)
S.a(S.a<0)=[];
S.b(S.b<0)=[];
S.c(S.c<0)=[];
S.d(S.d<0)=[];
S.e(S.e<0)=[];
S.a=double(S.a);
S.b=double(S.b);
S.c=double(S.c);
S.d=double(S.d);
S.e=double(S.e);
end
A positive response is awaited

コミュニティ

カテゴリ

ヘルプ センター および File Exchange で Programming についてさらに検索

製品

質問済み:

2019 年 10 月 11 日

回答済み:

2020 年 11 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by