solve a system of equations.

Could any one please help me write the code to solve this system of equations?
Fcl=1/(1+0.155*Iclo*h);
hr=4*5.67*0.00000001*0.72*facl*((0.5*(Tcl+To)+273)^3);
To=(hr*Tr+hc*Ta)/h;
Tcl=To+Fcl(Tsk(i)-To);
h=hc+hr;
Unknown: Fcl hr To Tcl h.
Others are known.
I'm a beginner, I follow the format but error always shoot out. Want quick respond thank you.

1 Comment

jin wang
jin wang on 12 Oct 2015
Edited: jin wang on 12 Oct 2015
What I wrote is like these.
syms Fcl hr To Tcl h
eqn1 = Fcl==1/(1+0.155*Iclo*h);
eqn2 = hr==4*5.67*0.00000001*0.72*facl*((0.5*(Tcl+To)+273)^3);
eqn3 = To==(hr*Tr+hc*Ta)/h;
eqn4 = Tcl==To+Fcl(Tsk(i)-To);
eqn5 = h==hc+hr;
[Fcl,hr,To,Tcl,h] = solve([eqn1,eqn2,eqn3,eqn4,eqn4,eqn5],[Fcl,hr,To,Tcl,hl])

Sign in to comment.

 Accepted Answer

Is Fcl a function or a value? If it is a value then you need explicit multiplication with respect to (Tsk(i)-To)
Note that by default "i" refers to sqrt(-1) so your Tsk(i) may be trying to index Tsk(sqrt(-1)) unless you have assigned something else to i
The statements you show by themselves are not enough: you need to define numeric values for the other variables or you need to declare them as syms . If you take the syms route then I recommend changing Tsk(i) to just plain Tsk since the indexing does not matter to the solution of the equations.
The solution involves the roots of a polynomial of degree 7 whose leading term is equivalent to
158193*Iclo*facl*(31*Iclo*Ta*hc-31*Iclo*Tr*hc-200*Tr+200*Tsk(i))^3 * x^7
Because it is a 7 degree polynomial, the answer you get is going to be in terms of RootOf() and there is unlikely to be a closed form solution in the standard operations. You are going to need to solve for numeric roots by using vpasolve() or using double()

15 Comments

Thank you for your help.
All the unknowns, including Fcl, are value and not function.And all the other symbols are given a specific value before I solve this system of equation. So it should be just like 5 unknowns and five equations problem. And the index i is used for a for loop, since this system of equations will be solved many times. Forgive me since I am a Matlab starter. I tried to use vpasolve() but still not working.
What is the result you get from vpasolve() ?
The error is shown:
Error using sym/subsindex (line 732) Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.
Error in sym/subsref (line 771) R_tilde = builtin('subsref',L_tilde,Idx);
Error in test (line 138) eqn4 = Tcl==To+Fcl(Tsk(k)-To);
eqn4 = Tcl==To+Fcl*(Tsk(k)-To);
Best wishes
Torsten.
Thank you. I correct it. But still got error:
Error using symengine (line 59) The dimensions do not match.
Error in sym/privBinaryOp (line 903) Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in * (line 244) X = privBinaryOp(A, B, 'symobj::mtimes');
Substitute "hl" by "h" in your call to "solve":
[Fcl,hr,To,Tcl,h] = solve([eqn1,eqn2,eqn3,eqn4,eqn4,eqn5],[Fcl,hr,To,Tcl,h])
instead of
[Fcl,hr,To,Tcl,h] = solve([eqn1,eqn2,eqn3,eqn4,eqn4,eqn5],[Fcl,hr,To,Tcl,hl])
If this still does not work, post again the complete code you are using.
Best wishes
Torsten.
I did point out that you needed that explicit multiplication...
function RC = rcloss(k,hc,Iclo,facl,Ta,Tsk,Tr)
%solving multiple equations:
syms Fcl hr To Tcl h
eqn1 = Fcl-(1/(1+(0.155*Iclo*h)));
eqn2 = hr-(4*5.67*0.00000001*0.72*facl*((0.5*(Tcl+To)+273)^3));
eqn3 = To-((hr*Tr+hc*Ta)/h);
eqn4 = Tcl-(To+Fcl*(Tsk(k)-To));
eqn5 = h-hc-hr;
[Fcl,hr,To,Tcl,h] = vpasolve(eqn1,eqn2,eqn3,eqn4,eqn5);
RC=Fcl*h*(Tsk(k)-To);
end
And the error says:
Error using symengine (line 59)
The dimensions do not match.
Error in sym/privBinaryOp (line 903)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in * (line 244)
X = privBinaryOp(A, B, 'symobj::mtimes');
Error in rcloss (line 10)
RC=Fcl*h*(Tsk(k)-To);
Error in test (line 133)
RC=rcloss(k,hc,Iclo,facl,Ta,Tsk,Tr);
Are any of your parameters vectors or matrices, other than Tsk ?
Note that you are expecting multiple results (7 of them), so you are asking to multiply vectors by vectors. You should consider
RC = Fcl .* h .* (Tsk(k)-To);
I define Fcl,h and To as syms as u can see. But when I check the workspace, I found that Fcl,h,and To are all 7x1 sym which includes a column of 1x1 syms.I don't know why this happens.
Because you get 7 solutions for your system ...
Best wishes
Torsten.
Okay. Thank you so much. I understand now.But if I only need one solution so that the dimension would match later-on equation solvings. What should I do?
How would you know which of the 7 solutions is the right one? For example do you know that for one of the variables, the imaginary part of the variable is negative?
Exactly, so I should use this 7 sloution matrix to substitute into the following calculation? I keep receiving dimension not match error.
Let's say I want to use RC and E which is 7x1 sym in the following code like this. How can I achieve this outcome?
Tsk(1+k,1)=Tsk(k,1)+deltat*(F(5)*(H(5)+(K(4)*(Tvsk(k,1)-Tsk(k,1)))-(RC+E)));

Sign in to comment.

More Answers (2)

John BG
John BG on 12 Oct 2015
Could you please define ranges for each unknown? Be conservative, please define the following: Fcl_min= Fcl_max= hr_min= hr_max= To_min= To_max= Tcl_min= Tcl_max= h_min= h_max=

1 Comment

you mean give them specific value or just write what you have writen in the code. I don't know why to do this.

Sign in to comment.

Mr Robertson considers as variables parameters that Mr Wang does not want to include as variables. I asked Mr Wang to define ranges because if the symbolic analysis does not help, then having a look at the equations may be useful, let me explain:
Since Mr Wang does not say anything else about the parameters, let me list them
eq1: Iclo assumed constant
eq2: facl and Tc assumed constant
eq3: Tr, Ta and hc assumed constant
eq4: Tsk(i) assumed constant
eq5: as in eq3, hc assumed constant
So, we have 5 variables to solve: Fcl hr To Tcl h
that I rename to: x y z w v
The simplified version of the 5 initial equations is:
eq1: x=1/(1+v)
eq2: y=((1+z)*.5+2)^3
eq3: z=(y+1)/v
eq4: w=z+x*(1-z)
eq5: v=1+y
I have define 5 ranges, that some of them may or may not help solve the system, but at least it's a start point:
x_min=-10;x_max=10;x_step=.1;x_range=[x_min:x_step:x_max]
y_min=-10;y_max=10; y_step=.1; y_range=[y_min:y_step:y_max]
z_min=-10;z_max=10; z_step=.1; z_range=[z_min:z_step:z_max]
w_min=-10;w_max=10; w_step=.1; w_range=[w_min:w_step:w_max]
v_min=-10;v_max=10; v_step=.1; v_range=[v_min:v_step:v_max]
now
v=v_range
x=1./(1+v)
figure(1);plot(v,x);grid on;hold all
z=z_range
y=((1+z)*.5+2).^3
figure(2);plot(z,y);grid on;w=z+x*(1-z)
simplifying some equations is possible:
eq3 and eq5 yield z=(y+1)/(1+y) nearly constant
eq4 with z nearly constant means w shape is w=1+x
I said 'nearly constant' because the simplified equations do not include the the parameters
Including parameters: Iclo facl Tc Tr Ta Tsk(i) hc
renamed: k1 k2 k3 k4 k5 k6 k7
eq1: x=1/(1+k1*v)
eq2: y=k2*((k3+z)*.5+2)^3
eq3: z=(k4*y+k5*k7)/v
eq4: w=z+x*(k6-z)
eq5: v=k7+y
give values to parameters, and find out if the 5 equations have a solution, or if perhaps the only way to solve this equations system is for values of parameters and variables within certain range windows.
Let me know if you progress with anything above explained
John

Asked:

on 12 Oct 2015

Answered:

on 31 Jan 2016

Community Treasure Hunt

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

Start Hunting!