Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
Help! With Systems of Equation solver 'syms'

Subject: Help! With Systems of Equation solver 'syms'

From: Jas

Date: 4 Jun, 2014 15:38:13

Message: 1 of 3

Hi everyone,

I sincerely hope someone will be able to assist me with an issue I have been having with the code.

I am trying to create a system of equations solver for 7 variables, listed below. Whenever the code is processed, it provides a series of errors, beginning with sym>checkindex (line2429) 'Index must be a positive integer or logical. It then proceeds with Error in sym>privformatscalar, sym>privformat, and sym/subsref.

The problem I am having with the equation is below. For the time being, there are several additional input variables that can be assigned as:

a = 0.7;
dh = .016;
length = 1000;
rho_gas = 0.07523*0.5;
Q_in = 4000/36000;
mdot_in = Q_in*rho_gas;
P_in = 10

A_1 = 3;
A_2 = A_1;
A_3 = A_1;
A_4 = A_1;

D_1 = 17/36;
D_2 = 12/36;
D_3 = 8/36;
D_4 = 5/36;

syms P_1 P_2 P_3 mdot_1 mdot_2 mdot_3 mdot_4

S = solve (P_in + 0.5*(mdot_in/(rho_gas*A_in))^2 == P_1 + 0.5*(mdot_1/(rho_gas*A_1))^2 + (-.015*(length/dh*((rho_gas*(mdot_1/(rho_gas*A_1))^2)/2)) - a*(length/dh*(mdot_1/(rho_gas*A_1))^2)), P_in + 0.5*(mdot_in/(rho_gas*A_in))^2 == P_3 + 0.5*(mdot_4/(rho_gas*A_4))^2 + (-.015*(length/dh*((rho_gas*(mdot_4/(rho_gas*A_4))^2)/2)) - a*(length/dh*(mdot_4/(rho_gas*A_4))^2)), P_1 + 0.5*(mdot_1/(rho_gas*A_1))^2 + (-.015*(length/dh*((rho_gas*(mdot_1/(rho_gas*A_1))^2)/2)) - a*(length/dh*(mdot_1/(rho_gas*A_1))^2)) == P_2 + 0.5*(mdot_2/(rho_gas*A_2))^2 + (-.015*(length/dh*((rho_gas*(mdot_2/(rho_gas*A_2))^2)/2)) - a*(length/dh*(mdot_2/(rho_gas*A_2))^2)), P_3 + 0.5*(mdot_4/(rho_gas*A_4))^2 + (-.015*(length/dh*((rho_gas*(mdot_4/(rho_gas*A_4))^2)/2)) - a*(length/dh*(mdot_4/(rho_gas*A_4))^2)) == P_2 + 0.5*(mdot_3/(rho_gas*A_3))^2 + (-.015*(length/dh*((rho_gas*(mdot_3/(rho_gas*A_3))^2)/2)) -
a*(length/dh*(mdot_3/(rho_gas*A_3))^2)), (mdot_4/(rho_gas*A_4)) == (mdot_3/(rho_gas*A_3)) + D_3, (mdot_2/(rho_gas*A_2)) + (mdot_3/(rho_gas*A_3)) == D_2, (mdot_1/(rho_gas*A_2)) == (mdot_2(rho_gas*A_2)) + D_1);



Thank you in advance!
cpbog1

Subject: Help! With Systems of Equation solver 'syms'

From: Christopher Creutzig

Date: 16 Jun, 2014 07:02:38

Message: 2 of 3

On 6/4/14 5:38 PM, Jas wrote:

> The problem I am having with the equation is below. For the time being, there are several additional input variables that can be assigned as:

Your code also contains an A_in, which you have not defined.

> S = solve (P_in + 0.5*(mdot_in/(rho_gas*A_in))^2 == P_1 + 0.5*(mdot_1/(rho_gas*A_1))^2 + (-.015*(length/dh*((rho_gas*(mdot_1/(rho_gas*A_1))^2)/2)) - a*(length/dh*(mdot_1/(rho_gas*A_1))^2)), P_in + 0.5*(mdot_in/(rho_gas*A_in))^2 == P_3 + 0.5*(mdot_4/(rho_gas*A_4))^2 + (-.015*(length/dh*((rho_gas*(mdot_4/(rho_gas*A_4))^2)/2)) - a*(length/dh*(mdot_4/(rho_gas*A_4))^2)), P_1 + 0.5*(mdot_1/(rho_gas*A_1))^2 + (-.015*(length/dh*((rho_gas*(mdot_1/(rho_gas*A_1))^2)/2)) - a*(length/dh*(mdot_1/(rho_gas*A_1))^2)) == P_2 + 0.5*(mdot_2/(rho_gas*A_2))^2 + (-.015*(length/dh*((rho_gas*(mdot_2/(rho_gas*A_2))^2)/2)) - a*(length/dh*(mdot_2/(rho_gas*A_2))^2)), P_3 + 0.5*(mdot_4/(rho_gas*A_4))^2 + (-.015*(length/dh*((rho_gas*(mdot_4/(rho_gas*A_4))^2)/2)) - a*(length/dh*(mdot_4/(rho_gas*A_4))^2)) == P_2 + 0.5*(mdot_3/(rho_gas*A_3))^2 + (-.015*(length/dh*((rho_gas*(mdot_3/(rho_gas*A_3))^2)/2)) -
> a*(length/dh*(mdot_3/(rho_gas*A_3))^2)), (mdot_4/(rho_gas*A_4)) == (mdot_3/(rho_gas*A_3)) + D_3, (mdot_2/(rho_gas*A_2)) + (mdot_3/(rho_gas*A_3)) == D_2, (mdot_1/(rho_gas*A_2)) == (mdot_2(rho_gas*A_2)) + D_1);

Your errors come from the mdot_2(rho_gas*A_2) near the end.

To search for such errors, it's usually a good idea to iteratively
reduce the input little by little – in this case, you could have started
leaving out the first equation, leaving out the first and second
equations, etc., each time checking if the error is still there.


HTH,

Christopher

Subject: Help! With Systems of Equation solver 'syms'

From: Steven Lord

Date: 16 Jun, 2014 14:00:50

Message: 3 of 3


"Christopher Creutzig" <Christopher.Creutzig@mathworks.com> wrote in message
news:539E968E.9020408@mathworks.com...
> On 6/4/14 5:38 PM, Jas wrote:
>
>> The problem I am having with the equation is below. For the time being,
>> there are several additional input variables that can be assigned as:
>
> Your code also contains an A_in, which you have not defined.
>
>> S = solve (P_in + 0.5*(mdot_in/(rho_gas*A_in))^2 == P_1 +
>> 0.5*(mdot_1/(rho_gas*A_1))^2 +
>> (-.015*(length/dh*((rho_gas*(mdot_1/(rho_gas*A_1))^2)/2)) -
>> a*(length/dh*(mdot_1/(rho_gas*A_1))^2)), P_in +
>> 0.5*(mdot_in/(rho_gas*A_in))^2 == P_3 + 0.5*(mdot_4/(rho_gas*A_4))^2 +
>> (-.015*(length/dh*((rho_gas*(mdot_4/(rho_gas*A_4))^2)/2)) -
>> a*(length/dh*(mdot_4/(rho_gas*A_4))^2)), P_1 +
>> 0.5*(mdot_1/(rho_gas*A_1))^2 +
>> (-.015*(length/dh*((rho_gas*(mdot_1/(rho_gas*A_1))^2)/2)) -
>> a*(length/dh*(mdot_1/(rho_gas*A_1))^2)) == P_2 +
>> 0.5*(mdot_2/(rho_gas*A_2))^2 +
>> (-.015*(length/dh*((rho_gas*(mdot_2/(rho_gas*A_2))^2)/2)) -
>> a*(length/dh*(mdot_2/(rho_gas*A_2))^2)), P_3 +
>> 0.5*(mdot_4/(rho_gas*A_4))^2 +
>> (-.015*(length/dh*((rho_gas*(mdot_4/(rho_gas*A_4))^2)/2)) -
>> a*(length/dh*(mdot_4/(rho_gas*A_4))^2)) == P_2 +
>> 0.5*(mdot_3/(rho_gas*A_3))^2 +
>> (-.015*(length/dh*((rho_gas*(mdot_3/(rho_gas*A_3))^2)/2)) -
>> a*(length/dh*(mdot_3/(rho_gas*A_3))^2)), (mdot_4/(rho_gas*A_4)) ==
>> (mdot_3/(rho_gas*A_3)) + D_3, (mdot_2/(rho_gas*A_2)) +
>> (mdot_3/(rho_gas*A_3)) == D_2, (mdot_1/(rho_gas*A_2)) ==
>> (mdot_2(rho_gas*A_2)) + D_1);
>
> Your errors come from the mdot_2(rho_gas*A_2) near the end.
>
> To search for such errors, it's usually a good idea to iteratively
> reduce the input little by little in this case, you could have started
> leaving out the first equation, leaving out the first and second
> equations, etc., each time checking if the error is still there.

Or define intermediate variables, like T1 = mdot_1/(rho_gas*A_1), T2 =
mdot_2/(rho_gas*A_2), etc. for terms that appear repeatedly in your
equations. This would also make your equations shorter and IMO easier to
read, which may help in validating that you're solving the equations you
think you are. [For example, in your last equation, is that supposed to be
mdot_1/(rho_gas*A_2) or should it be either T1 or T2? Nowhere else in your
code do the mdot subscript and the A subscript differ.]

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us