How to solve a symbolic equation that uses conditional statements?

25 vues (au cours des 30 derniers jours)
Alexis
Alexis le 12 Sep 2023
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 commentaires
Walter Roberson
Walter Roberson le 12 Sep 2023
piecewise()
Nathan Hardenberg
Nathan Hardenberg le 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?

Connectez-vous pour commenter.

Réponse acceptée

Alexis
Alexis le 12 Sep 2023
Déplacé(e) : Walter Roberson le 12 Sep 2023
Walter and Nathan,
Yes, with a piecewise() now it works. I also used assume(c_, 'positive') and used this sigma function
function sigma = sigmaReinf(es, fy, Es)
sigma = sym(zeros(length(es),1));
for i = 1:length(es)
sigma(i) = piecewise(abs(es(i)) < fy/Es, es(i)*Es, abs(es(i)) >= fy/Es, sign(es(i))*fy);
end
end
Thank you both so much.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by