How to solve a symbolic equation that uses conditional statements?
27 views (last 30 days)
Show older comments
Hello everyone,
I'm currently facing the following issue:
I need to solve an equation with a single variable "c_". But, this equation relies on a function called "sigmaSteel", note that this function uses a symbolic vector variable. The code I've developed is the following:
% I've all the double variables (fc=300,beta1_val=0.83, b=30, as=[11.4040; 11.4040], fy=4200, Es=2.1*10^6, Pu=0, ecu=0.003)
% defined above this section. Here I'm looking to determine the value of c_ and then save it in c as a double.
d = [5; 55];
syms c_ % c_ must be real and positive
es = (c_ - d)/c_*ecu; % this is a vector in function of c_ (symbolic)
eqn = 0.85*fc*beta1_val*c_*b + sum(as.*sigmaSteel(es,fy,Es)) - Pu; % eqn == 0
c = solve(eqn,c_);
c = double(c)
I think, that the problem is in my sigmaSteel() function. I can't find a way to convince matlab that I want the "condition" (if abs(es) < fy/Es so the value of sigma is ... ) to be incorporated into the equation as a symbolic variable.
% This function takes "es" that is a symbolic variable (or a vector of symbolic variables as ca), and if "es" is greater than fy/Es (fy/Es is a double) then return
% es*Es for that row of the vector if not so return sign(es)*fy. Note that this is because sigma is es*Es until a limit that is the value of fy or -fy
function sigma = sigmaSteel(es, fy, Es)
sigma = sym(zeros(length(es),1));
condition = abs(es) <= fy/Es; %% How to change this line to work with vector of symbolic variables?
sigma(condition) = es(condition)*Es;
sigma(~condition) = sign(es(~condition))*fy;
end
Note that abs(es) <= fy/Es does not work with symbolic variables, I cant work with the numerical es values because
the're in function of c_ that is the value that I want to determine using solve(eqn,c_).
The way that I used to solve this is to make assumptions, for example:
% if es < fy/Es --> sigma = es*Es. The equation that I've to use to find
% c_ is:
eqn = 0.85*fc*beta1_val*c_*b + as*(es*Es) - Pu;
And if the assumption is incorrect (I just have to evaluate c in es = (c-d)/c*ecu), so I switched to the opposite assumption:
% if es > fy/Es --> sigma = fy. The equation that I've to use to find c_
% is:
eqn = 0.85*fc*beta1_val*c_*b + as*(fy) - Pu;
As you see, this approach is not efficient, specially when there is no only one layer of steel (as1*fy + as2(es*Es) + as3*(fy)..... and all the possible combinations for multiple layers).
I'm open to any solution to address this issue, even if it requires a significant change. My primary goal is to successfully solve this equation.
Best regards,
2 Comments
Nathan Hardenberg
on 12 Sep 2023
In your condition you write: , but es is a 2D-vector and is a scalar. This gives you two conditions. What do you want to do with that?
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!