solve failing on some values.

2 views (last 30 days)
Ecor
Ecor on 23 Oct 2015
Commented: Ecor on 4 Nov 2015
hi and thank you for the attention.
i'm trying to use Matlab to write a code on waste waters pipes sizingfor my college thesis. i have started since one year ago and i did more tries
i have this problem that i will write and i don't know how to fix it.
it consist in it : i use GDRC = solve( eqn == value , GDR ), it works for more values that i give in input passing them as datas to the function that contains GDRC , but failes for some of them, saying me
" Warning: Explicit solution could not be found. > In solve at 179 In GDRC at 17 In Main at 45 Error using sym/eval (line 11) Error: This statement is incomplete.
Error in GDRC (line 17) GDRC = eval(solve ( Q_Prog == Q , GDR ) ) ;
Error in Main (line 45) [Val_Comm] = GDRC ( GS, Q_Prog, j, Ris_Prog(5) )"
my code ( and functions) ( see below ) is based on no-linear problem. for same datas, excell solver and maple one find a real value of GDR and it is the same for both, why matlab not?
Main
clear all
% Dati di prova ----------------------------------------
Q_Prog = 0.030 % changing and encreasing this value Dimensionamento sizes the diameter but GDRC gives error 8 it recalculates idraulic parameters for common pipes ( bigger than calculated teorical diameter in dimensionamento)
%
%
% Q_Prog = 0.04
%
% GS = 70 ;
%
% L = 370 ;
%
% z_i = 53 ;
%
% z_f = 52 ;
%
%
GS = 70 ;
L = 370 ;
z_i = 53 ;
z_f = 52 ;
j = ( z_i - z_f) / L ;
GDR_Prog = 0.75 ;
%-------------------------------------------------------
% Diametro teorico e relativi valori idraulici ed inviduazione
% diametro commerciale --------------------------------
[Ris_Prog] = Dimensionamento( GDR_Prog, Q_Prog, GS, j )
% valori idraulici relativi diametro commeciale
% ed eventuale cambio pendenza --------------------------
[Val_Comm] = GDRC ( GS, Q_Prog, j, Ris_Prog(5) )
dimensionamento ( sizing )
function [ Ris_Prog ] = Dimensionamento( GDR_Prog, Q_Prog, GS, j )
clear beta A R chi D DC
syms DT real
beta = 2 * acos( 1 - 2 * GDR_Prog ) ;
A = ( DT ^ 2 / 8) * ( beta - sin( beta ) ) ;
R = ( DT / 4 ) * ( 1 - ( sin( beta ) / beta ) ) ;
chi = GS * R ^ ( 1 / 6 ) ;
Q = chi * A * R ^ ( 1 / 2 ) * j ^ ( 1 / 2) ;
DT = eval( solve ( Q_Prog == Q , DT ) ) ;
D = [ 200: 50 : 2000 ] ;
A = eval ( subs ( A , DT , DT ) ) ;
R = eval ( subs ( R , DT , DT ) ) ;
chi = eval ( subs ( chi , R , R ) ) ;
for a = 1 : length ( D )
if D(a) / 1000 >= DT
DC = D(a) / 1000 ;
break
end
end
Ris_Prog = [ DT, A, R, chi, DC ] ;
end
GDRC ( values for real diameters in shops )
function [Val_Comm] = GDRC ( GS, Q_Prog, j, DC )
clear GDR beta A R chi AC chiC RC GDRC
syms GDR real
beta = 2 * acos( 1 - 2 * GDR ) ;
A = ( DC ^ 2 / 8 ) * ( beta - sin(beta) ) ;
R = ( DC / 4 ) * ( 1 - ( sin(beta) / beta )) ;
chi = GS * R ^ ( 1 / 6 ) ;
Q = chi * A * R ^ ( 1 / 2 ) * j ^ (1 / 2 ) ;
GDRC = eval(solve ( Q_Prog == Q , GDR ) ) ;
betaC = eval( subs(beta, GDR, GDRC )) ;
AC = eval( subs(A, GDR, GDRC )) ;
RC = eval( subs(R, GDR, GDRC )) ;
chiC = eval( subs(chi, GDR, GDRC )) ;
v_c = Q_Prog / AC ;
Val_Comm = [ GDRC, betaC, AC, RC, chiC, v_c ] ;
end
  1 Comment
Ecor
Ecor on 4 Nov 2015
i successed to find solutions using vpasolve.
GDRC = eval(vpasolve( Q_Prog == Q , GDR,[0.0001 , 0.75] ) ) ;
at this point i think there is a bug in solve script and i will try to report this error to MATLAB report bug.
thank you again for your attention

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 23 Oct 2015
Never eval() a symbolic formula. Symbolic formula are written in a language which is not exactly the same as MATLAB, so the results are not going to be what you want.
If you have a symbolic formula that you want to evaluate into a number, then use double() on the formula.
  1 Comment
Ecor
Ecor on 23 Oct 2015
hi and thanks for your answer. the problem persist also using double, as you wrote, and don't using eval( solve (..., gdr)
if i change gdr from "syms GDR real" to " syms GDR " it works but it finds complex numbers.
also if i encrease the diameter, GDRc fuction works. this truely weird for me.
thank you again.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!