How would I write a code to solve a system of equations?

16 ビュー (過去 30 日間)
Omar
Omar 2013 年 10 月 19 日
回答済み: anjali wavhale 2020 年 12 月 1 日
I need to solve a system of equations but I do not know the syntax for doing so. The equations are:
q1 = (1.53*10^-5)*t1^4 + (1.67*10^-2)*t1^3 + 6.85*t1^2 + 2746*t1 - 57793
q2 = 13.3*(t1-t2)
q3 = (1.53*10^-5)*t2^4 + (1.67*10^-2)*t2^3 + 6.85*t2^2 + 4846*t2 - 49161
also; q1=q2=q3
I'm new to MATLAB and not sure how to handle this many variables along with the scientific notation.
  2 件のコメント
Qasim Manzoor
Qasim Manzoor 2013 年 10 月 19 日
do you have to use a mathematical method or any way would be fine?
Omar
Omar 2013 年 10 月 20 日
I don't know what you mean exactly. How would you solve this in a non-mathematical way?

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

回答 (4 件)

sixwwwwww
sixwwwwww 2013 年 10 月 20 日
編集済み: sixwwwwww 2013 年 10 月 20 日
Dear Omar, you can solve your system of equations using the following way:
t = sym('t%d', [1 2]);
q1 = 1.53e-5 * t(1)^4 + 1.67e-2 * t(1)^3 + 6.85 * t(1)^2 + 2746 * t(1) - 57793;
q2 = 13.3 * (t(1) - t(2));
q3 = 1.53e-5 * t(2)^4 + 1.67e-2 * t(2)^3 + 6.85 * t(2)^2 + 4846 * t(2) - 49161;
[solutions_t1, solutions_t2] = solve(q1 == q2 == q3, t(1), t(2))
Or
[solutions_t1, solutions_t2] = solve(q1 == q2, q2 == q3, t(1), t(2))
You can check which solutions are better because in first case you will get 4 solutions for both t1 and t2 and in second case you will get 16 solutions for both t1 and t2. I hope it helps. Good luck!
  25 件のコメント
Omar
Omar 2013 年 10 月 20 日
ok I got what I'm looking for. Thank you for your help.
sixwwwwww
sixwwwwww 2013 年 10 月 20 日
You are welcome dear

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


Walter Roberson
Walter Roberson 2013 年 10 月 20 日
{q = 2003.839045, t1 = -819.5264017, t2 = -970.1909915},
{q = -10982.94224, t1 = -817.9943073, t2 = 7.790823431},
{q = 133.2164095, t1 = 20.04280634, t2 = 10.02653495},
{q = 13235.45859, t1 = 24.30348638, t2 = -970.8437757}
provided that you only want real-valued solutions.
This was done by substituting t1 for t(1) and t2 for t(2), and then plugging the three q equations into solve()

David
David 2013 年 10 月 21 日
編集済み: David 2013 年 10 月 21 日
In addition to the answers already posted, be sure to put sym() around each of your equations. That is to say, do the following:
syms t1 t2
q1 = sym( 1.53e-5*t(1)^4 + 1.67e-2*t(1)^3 + 6.85*t(1)^2 + 2746*t(1) - 57793 );
q2 = sym( 13.3*(t(1) - t(2)) );
q3 = sym( 1.53e-5*t(2)^4 + 1.67e-2*t(2)^3 + 6.85*t(2)^2 + 4846*t(2) - 49161 );
[solutions_t1, solutions_t2] = solve(q1 == q2, q2 == q3, t1, t2);
solve requires that your equations be symbolic objects which is guaranteed by using sym().
  2 件のコメント
Walter Roberson
Walter Roberson 2013 年 10 月 21 日
As long as anything in the equation is sym, the whole expression will be treated as sym. So
t = sym('t%d', [1 2]);
is enough to make the equations sufficiently sym() without requiring sym() around the equations.
David
David 2013 年 10 月 22 日
Oh? This seemed to correct a problem I was having earlier in using the solve function. You actually saw that question and made useful suggestions, though suggestions that did not quite do the trick. Maybe we are both missing something or maybe it's just me...

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


anjali wavhale
anjali wavhale 2020 年 12 月 1 日
how to do least square estimation for system with the prbs as input to it

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by