how to optimize coefficients of symbolic integral?
2 次查看(过去 30 天)
显示 更早的评论
I have a symbolic integral with symbolic parameters (x(1), x(2),x(3),t). I am trying to fit this symbolic integral to experimental data and acquire those parameteres (x(1),x(2),x(3)). I tried to use fminsearch or fmincon; however, I couldn't use them and I faced different errors. for example: is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated: Error while trying to evaluate FITTYPE function
clear all;
clc;
beta=0.002;
alfa=0.004;
nu=0.49;
del=0.010;
t0=1.35;
syms eta G1 G2 A s t taw
x=sym('x',[1 3]);
p1=(eta)/(G1+G2);
q1=(2*G1*eta)/(G1+G2);
q0=(2*G1*G2)/(G1+G2);
B1=(2*G1*(1+nu))/(3*(1-2*nu));
B2=(2*G2*(1+nu))/(3*(1-2*nu));
B3=(2*eta*(1+nu))/(3*(1-2*nu));
q2=3*B1*B2/(B1+B2);
q3=B3/(B1+B2);
q4=3*B1*B3/(B1+B2);
Pc1=1+p1*A;
Qc1=q0+q1*A;
Pc2=1;
Qc2=q2;
f1=Pc1*Qc2*Pc1+2*Pc1*Pc2*Qc1;
c1 = coeffs(f1, A);
c1=simplify(c1);
f2=2*Pc1*Qc1*Qc2+Qc1*Pc2*Qc1;
c2=coeffs(f2,A);
c2=simplify(c2);
GG2=ilaplace((4*beta/(3*t0*sqrt(alfa)))*del*(c2(1,3)*s^2+c2(1,2)*s+c2(1,1))/((c1(1,3)*s^3+c1(1,2)*s^2+c1(1,1)*s)), t);
GGs2=subs(GG2, t, t-taw);
GGss2=subs(GGs2, {G1,G2,eta}, {x(1),x(2),x(3)});
assume(x(1) > 0)
assume(x(2) > 0)
assume(x(3) > 0)
assume(x(1),'real')
assume(x(2),'real')
assume(x(3),'real')
force2=int(GGss2*diff(taw^1.5,taw),taw,0,t0,'IgnoreAnalyticConstraints',true);
t0=[2 12 22 32 42 52 62 72 82 92 102 112];
F0=[0.77618 0.7259 0.70212 0.7011 0.69315 0.69324 0.67682 0.67658 0.67618 0.67669 0.67623 0.66831];
B2 = simplify(force2);
F2 = matlabFunction(B2,'vars', [{x(1),x(2),x(3)},t]);
%---------------------------------Error------------------------------------
funcfit1=fittype(F2,'indep','t','coefficients', {'x1','x2','x3'});
%--------------------------------------------------------------------------
F22=subs(numinteg, t, t0);
% fminsearch algorithm
fun = sum((F0-F22).^2);
%starting guess
pguess = [1000,1000,1000];
%optimise
[p,fminres] = fminsearch(fun,pguess)
2 个评论
Walter Roberson
2016-11-14
assume greater than zero implies assume real so the second round of assune would not be necessary. Also, calls to assume on the same object overwrite each other, and you would need assumealso (check spelling) to add an assumption.
Generally speaking, integral equations often have no symbolic solution. If the integrals have closed form solutions then you would substitute the closed form solutions and then you would not be trying to solve simultaneous integrals.
回答(1 个)
Walter Roberson
2016-11-14
Okay, so the error message you get is
Error using fittype/testCustomModelEvaluation (line 12)
Expression
x1.^2.*1.0./(x1+x2).^2.*1.0./sqrt(-(x1+x2)./x3).*(sqrt(1.5e1).*x3.*exp(((t.*2.0e1-2.7e1).*(x1+x2).*(-1.0./2.0e1))./x3).*sqrt(-(x1+x2)./x3).*6.0-x3.*sqrt(pi).*erf(sqrt(1.5e1).*sqrt(-(x1+x2)./x3).*(3.0./1.0e1)).*exp(-(t.*(x1+x2))./x3).*1.0e1).*2.342427896421022e-5+(sqrt(1.5e1).*x1.*x2.*4.960435545362163e-4)./(x1+x2)+x1.^2.*x3.*exp((x2.*(t.*4.0e1-2.7e1).*(x1+x2).*(-1.53e2./2.0e1))./(x3.*(x1.*4.0+x2.*1.53e2))).*1.0./(x1+x2).^2.*(sqrt(1.5e1).*exp((t.*x2.*(x1+x2).*1.53e2)./(x3.*(x1.*4.0+x2.*1.53e2))).*sqrt(-(x2.*(x1+x2))./(x3.*(x1.*4.0+x2.*1.53e2))).*1.53e2-sqrt(1.7e1).*sqrt(pi).*exp((x2.*(t.*2.0e1-2.7e1).*(x1+x2).*(1.53e2./2.0e1))./(x3.*(x1.*4.0+x2.*1.53e2))).*erf(sqrt(2.55e2).*sqrt(-(x2.*(x1+x2))./(x3.*(x1.*4.0+x2.*1.53e2))).*(9.0./1.0e1)).*5.0).*1.0./sqrt(-(x2.*(x1+x2))./(x3.*(x1.*4.0+x2.*1.53e2))).*2.613587118501084e-6
is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated:
Error while trying to evaluate FITTYPE function :
Input must be real and full.
Error in fittype>iCreateFittype (line 371)
testCustomModelEvaluation( obj );
Error in fittype (line 328)
obj = iCreateFittype( obj, varargin{:} );
Caused by:
Error using fittype/evaluate (line 84)
Error while trying to evaluate FITTYPE function :
Input must be real and full.
Notice the repeated "Input must be real and full". That message is coming from erf() or erfc() being evaluated with complex values. You have two erf() or erfc() in your expression; one of the two of them is
erf((3/10)*sqrt(15)*sqrt(-(x1+x2)/x3))
If sqrt(-(x1+x2)/x3) is complex then you would get that message. It would be complex if (x1+x2)/x3 is positive.
The fittype() function does not know anything about bounds of any kind, and is doing a cross-check to be sure that the provided function executes acceptably; in doing that testing, it probes with values that do not happen to meet the constraint (x1+x2)/x3 <= 0 so it is doing erf() of a complex value.
erf() from the Symbolic toolbox is able to handle complex inputs, producing complex results. However, you used matlabFunction so you crossed over to the numeric routines and the numeric routines give an error message for that situation.
Your code after that point does not use the result of fittype so we do not know if you had accounted for the constraint when you used the routine. I can see, though, that you later use fminsearch on a function: fminsearch is always unbounded and would almost certainly end up triggering the problem if you were to pass the function to fminsearch.
You will probably have to switch to generating a function from the sum of squares of values estimated using F2 compared to actual values, and then use that function with fmincon to put in bounds constraints or nonlinear constraints to prevent the problem.
Your other erf is
erf((9/10)*sqrt(255)*sqrt(-x2*(x1+x2)/(x3*(4*x1+153*x2))))
which has a more complex constraint which again would need to be handled by bounds constraints or nonlinear constraints.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!