Solving a system of multiple equations for multiple variables

13 views (last 30 days)
I'm trying to solve a system for the unknown variables, but it looks like my code is insufficient because of the long run time. I'm relatively new so my understanding is limited, and I'd like to know if my methods were along the right track. Also, how can I do this problem better? Thanks! (Apologies for the formatting, I don't know how to input this any better)
syms VT V1 V2 v1 v2 Re1 Re2 f1 f2 h
eqn1= v1== V1/(0.00125);
eqn2= v2== V2/0.00502;
eqn3= Re1== (39.92*v1)/0.001002;
eqn4= Re2== (79.84*v2)/0.001002;
eqn5= (1/f1^(1/2)) == -2*log(2.51/Re1*f1^(1/2));
eqn6 = (1/f2^(1/2)) == -2*log(2.51/Re2*f2^(1/2));
eqn7 = VT== V1+V2;
eqn8 = 8000==(VT*9790.38*h)/0.7;
h = 8;
sol = solve(eqn1, eqn2,eqn3,eqn4,eqn5,eqn6,eqn7,eqn8);

Answers (1)

John D'Errico
John D'Errico on 30 Apr 2017
Getting better. At least you made an effort this time.
But you have 8 equations, with 10 variables, one of which has a known value, thus h=8. But that leaves 8 essentially polynomial equations in 9 unknowns. You can't just "solve" such a problem, because infinitely many solutions may exist.
You will need to pick exactly one more variable to remain fixed. For example:
h = 8;
f1 = 17;
eqn1= v1== V1/(0.00125);
eqn2= v2== V2/0.00502;
eqn3= Re1== (39.92*v1)/0.001002;
eqn4= Re2== (79.84*v2)/0.001002;
eqn5= (1/f1^(1/2)) == -2*log(2.51/Re1*f1^(1/2));
eqn6 = (1/f2^(1/2)) == -2*log(2.51/Re2*f2^(1/2));
eqn7 = VT== V1+V2;
eqn8 = 8000==(VT*9790.38*h)/0.7;
sol = vpasolve(eqn1, eqn2,eqn3,eqn4,eqn5,eqn6,eqn7,eqn8)
sol =
struct with fields:
Re1: [1×1 sym]
Re2: [1×1 sym]
V1: [1×1 sym]
V2: [1×1 sym]
VT: [1×1 sym]
f2: [1×1 sym]
v1: [1×1 sym]
v2: [1×1 sym]
>> sol.Re1
ans =
11.683262215668314943450451980458
>> sol.Re2
ans =
1134868.0105447399597863690792349
>> sol.v1
ans =
0.00029325222294838808578439218553909
>> sol.v2
ans =
14.242707246566000983222412209372
  2 Comments
Jason  Maharaj
Jason Maharaj on 30 Apr 2017
Thank you! A few questions though. Why did you use vpasolve instead of solve? And when I tried out your version, I wasn't able to get numerical values, how would I go about doing this? The output displayed only the fields. And finally in your opinion, what's a good way to learn matlab outside of a course?
Karan Gill
Karan Gill on 1 May 2017
To learn MATLAB, try the doc. There's a nice Getting Started section for every part of MATLAB. Here's the Symbolic toolbox one: https://www.mathworks.com/help/symbolic/getting-started-with-symbolic-math-toolbox.html
About " vpasolve instead of solve", again the doc should tell you the difference between the two. Look at the vpasolve doc page: https://www.mathworks.com/help/symbolic/vpasolve.html
About " And when I tried out your version, I wasn't able to get numerical values ", you need to describe what happened when you tried John's code. Otherwise, it's hard for us to understand the problem.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!