MATLAB: How to make a solver with several functions containing a definite integration inside

conditional functionintegralintegrationsolve

Hi, I am relative new in matlab. I never use solver and definite integration in matlab. Normally I will do it numerically in excel so I can control my data easily. But due to some circumtances, I need to do it in matlab. In this question, I try to reduce the matrix size so I can easily explain. my problem is as below
constants
As=[2094.4 3272.53 4105; 3272.53 3272.53 4105;]; %>> matrix size (n,m) where n=number of cases and m=number of possible As
d=[950 950 950; 933.33 950 950;]; %>> matrix size (n,m) where n=number of cases and m=number of possible As >> d is the position of As
P=[-499.8 -499.8; -1122 -1122; 1122 499.8;]; %>> matrix size (k,n) where k=number of considered P in a case and n=number of cases
fy=415; fcd=24/1.3; k1=0.85; es=fy/200000; B=1000; Ty=fy*As;
functions variable (x,ec_top)
  1. ec_top=x*es/(d-x)
  2. sigma(ec)=k1*fcd*(ec/0.002)*(2-ec/0.002) for 0<ec<0.002
  3. sigma(ec)= k1*fcd for 0.002<ec<0.0035
  4. sigma(ec)= 0 for else
  5. Cc=B*integral(sigma(ec),0,ec_top)
Equation
Ty-Cc=P
as we can see that function 1 is the correlation of variable x and ec_top, further ec_top is used as upper limit in integration to solve the equation.
I want to solve the equation for each k,n,m and what I care is the value of x where the size suposse to be [k,n,m]
or x1 [k,m] and x2 [k,m] for each case. either way is ok for me. please help

Best Answer

You are working with symbolic x1 and ec, so you use symbolic forms.
I had to make some guesses about what the code was intended to mean
As=[2094.4 3272.53 4105; 3272.53 3272.53 4105;]; %>> matrix size (n,m) where n=number of cases and m=number of possible As
d=[950 950 950; 933.33 950 950;]; %>> matrix size (n,m) where n=number of cases and m=number of possible As >> d is the position of As
P=[-499.8 -499.8; -1122 -1122; 1122 499.8;]; %>> matrix size (k,n) where k=number of considered P in a case and n=number of cases
fy=415;
fcd=24/1.3;
k1=0.85;
es=fy./200000;
B=1000;
Ty=fy.*As;
syms ec x1
assume(ec > 0);
assume(x1 > 0 & x1 <= B);
%d is an array... so ec_top will be an array
ec_top = x1.*es./(d-x1);
%notice that sigma is 0 for ec == 0.002 exactly because both cases
%were defined with strict lower < value < upper rather lower <= value < upper
sigma = piecewise(0 < ec & ec < 0.002, k1.*fcd.*(ec./0.002).*(2-ec./0.002), ...
ec > 0.002 & ec<0.0035, k1.*fcd, ...
0);
%array ec_top is used as an upper bound on the integral. Does that mean you want
%an array of values, one for each upper bound? Or should the values somehow be
%constrained by case ??
Cc_temp = arrayfun(@(UB) int(sigma, ec, 0, UB), ec_top);
Cc = B .* Cc_temp;
eqn_lhs = Ty-Cc
%there are multiple P for each case, but each case has multiple As values.
%does that mean we want a solution for each (P,As) combination for each case?
for casenum = 1 : size(As,1)
for Pnum = 1 : size(P,1)
solutions(casenum,:,Pnum) = arrayfun(@solve, eqn_lhs(casenum,:)==P(Pnum,casenum), 'uniform', 0);
end
end
No solutions.
But this will give you a chance to review and figure out what your notation was intended to mean when brought into practice.
Si=double(solve(eqn,[ec,x>0||x<=B]));
What is x? Is it x1? Is the intention to confine x1 to the region 0 (exclusive) to 1000 (inclusive) ?
Under some assumptions it is possible to find solutions... if my interpretation of the question is correct, which is questionable.