solving system of 16 nonlinear equations with 16 unknowns

167 Views Asked by At

I am trying to solve a system of 16 nonlinear equations that has 16 unknowns using lsqnonlin.

my variables are all depend on other equations (exp: SegmaD is unknown and defined as (SegmaD= EpR2Teta) then (Teta= fcr-Epcr/2*FT) then Epcr=EpA/TX and as you can see EPA has an if statement so I defined all the variables as symbolic, but I am getting errors that you can't use if statement with symbolic (I am a beginner in Matlab) so I want to construct my 16 equations by substituting other ones that has the unknowns to solve by lsqnonlin, how can I do that symbolically and then solve for a given value? what is the best way to approach this? I have attached a part of my code to give a brief understanding of what is going on. Thanks

code:

syms Tx EpDs EpR EpA EpL K1 SegmaR Teta SegmaD FT EpT q AlphaD GamaLT
SegmaR(i) = Fcr*(EpR(i)/Epcr);
Teta(i) = 0.9/(sqrt(1+600*EpR(i))); % Teta is the Softening Coefficient equation 17

% K1 equation 16
if (EpA(i) < EpDs(i))    
    K1(i)= ((EpDs(i)/Ep0)*(1-(EpDs(i)/3*Ep0))-((EpA(i))^2)/(EpDs(i)*Ep0))*(1-((EpA(i)/3*Ep0)))*(EpDs(i)/(EpDs(i)-EpA(i))); 
elseif (EpA(i)==EpDs(i))    
    K1(i)= ((2*EpDs(i)*Ep0)-EpDs(i)^2/Ep0^2); %K1 is a Dimensionless Parameter   
end

SegmaD(i) = K1(i)*Teta(i)*fck; % SegmaD is the evolution of concrete compressive stress equation 15

EpT(i) = EpR(i)+EpD(i)-EpL(i); %equation 14

FT(i) = (Es*EpT(i))*(0.002+((1-0.002)/(1+((1-0.002)*(EpT(i)/EpSy))^4)^0.25)); % Equation 21
1

There are 1 best solutions below

0
On

First note that you only defined 14 symbolic variables and not 16 with syms. You should also check your parentheses again! Some are extra and some are missing. It is also not clear what you want to do in the end with these expressions. But anyways, one important thing is that a symbolic variable and a symbolic function or a variable and a function in general are not the same things. What I see is that EpR in your code is not a variable, but a function of t (I changed your i with t because t makes more sense for me such as time for example whereas i to me is usually an integer counter ^_^). To see how to define a symbolic function in Matlab see its help page https://uk.mathworks.com/help/symbolic/create-symbolic-functions.html or this one https://uk.mathworks.com/help/symbolic/symfun.html. One more thing is that when the equation of your function changes depending on some conditions, then in fact you have a piecewise function. Here is the help page for piecewise functions in Matlab https://uk.mathworks.com/help/symbolic/piecewise.html, and for definition of piecewise functions in general you can look at its Wikipedia page https://en.wikipedia.org/wiki/Piecewise. Here is how I rewrote your code. You may wonder why I have different lines of syms, it is just because I saw many symbols in your code that are not in your syms-line, so I looked at your code and add one syms for each symbol I encountered. You can make them in one line yourself. Now if you run this, you do not see any error message.

syms EpR( t )
syms Fcr
syms Epcr
syms SegmaR( t )
SegmaR( t ) = Fcr * ( EpR( t ) / Epcr );
syms Teta( t )
Teta( t ) = 0.9 / sqrt( 1 + 600 * EpR( t ) );
syms EpA( t )
syms EpDs( t )
syms Ep0
syms K1( t )
K1( t ) = piecewise( EpA( t ) < EpDs( t ), (EpDs( t ) / Ep0 ) * (1 - (EpDs( t )/ (3 * Ep0 ) )) - ((EpA( t ) ^ 2 ) / (EpDs( t ) * Ep0)) * (EpDs( t ) / (EpDs( t ) - EpA( t ))), EpA( t ) == EpDs( t ), 2 * EpDs( t ) * Ep0 - EpDs( t ) ^ 2 / Ep0 ^ 2 );
syms fck
syms SegmaD( t )
SegmaD( t ) = K1( t ) * Teta( t ) * fck;
syms EpR( t )
syms EpD( t )
syms EpL( t )
syms EpT( t )
EpT( t ) = EpR( t ) + EpD( t ) - EpL( t );
syms Es
syms EpSy
syms FT( t )
FT( t ) = Es * EpT( t ) * ( 0.002 + (1 - 0.002) / (1 + ((1 - 0.002) * (EpT( t ) / EpSy)) ^ 4) ^ 0.25);
% doing something to be sure symbolic functions are defined fine.
disp( diff( FT, t ));

Your "part of code" does not include any system of equations. You can edit your question and include it.