Solving symbolic equations that contain numeric integration

2 次查看(过去 30 天)
I am trying to solve several equations simultaneously. These equations have multiple variables, complex sine/cosine and triple integration. I have problems in both integration and equation solving. Here are my questions.
1. About integration: after integration, I need to get a function that still has several unknown parameters. should I use symbolic integration "int()" or numeric integration "dblquad()" if the function expression is really complex?
2. about equation solving: which way is faster, symbolic "solve()" or numeric like "fmincon()"? Here is my code for using "fmincon()". Is the logic right?
%%f1,f2,f3,f4 are four functions with four unknown variables x phi lamda4 lamda
out=(f1-1)^2+(f2-2)^2+(f3-3)^2+(f4-f4)^2;
syms x1
subs(out,x,x1(1));
subs(out,phi,x1(2));
subs(out,lamda2,x1(3));
subs(out,lamda4,x1(4));
x0=[pi/6 pi/6 -1 -2];
lb=[0 0 -20 -20];
ub=[2*pi 2*pi 0 0];
syms x1 clear;
[x1,fval,exitflag,output]=fmincon(out,x0,[],[],[],[],lb,ub);

采纳的回答

Walter Roberson
Walter Roberson 2011-1-21
If the function expression is really complex, then it becomes improbable that symbolic integration will be able to find a closed form solution, in which case numeric integration would be necessary anyhow. If, though, your f1, f2, f3, and f4 are multinomials (that is, can be written as the sum of terms that involve multiplying together non-negative integral powers of the variables), then expand(out) will produce an expression that can be mechanically integrated, which would be faster than numeric integration.
I would suggest, though, that in your expression for "out" that you want (f4-4)^2 instead of (f4-f4)^2
With regards to solving: it depends on the functions involved and their powers. If the expression can be rewritten as a polynomial in degree at most 4, or if it contains some other functions such as exp() or GAMMA() used in fairly narrow ways, then there are standard solutions which solve() can find faster than numeric solving would work. Symbolic solutions can also be important if all of the solutions must be found. If, though, it is simply important to find some solution over a known range (or it is known that only one solution exists in that range) then numeric solutions can end up being much much faster.
There is another consideration that comes in to play at times, and that is whether to use a solver at the Matlab level or to use one of the numeric solvers built in to the symbolic toolbox. For some problems, it can be critical to use the symbolic toolbox for numeric solutions, as the symbolic toolbox is able to use ranges of numbers beyond those available in IEEE binary floating point, and the symbolic toolbox is able to operate at extended accuracies (if you set the Digits higher.) When using higher-order polynomials or distributions near the tail ends, binary floating point calculations often slip in to numeric nonsense through loss of precision.
Your subs() code is not correct, as you are not assigning the results of the substitution to anything; the substituted expression is produced but then discarded before the next substitution starts. You can also combine several subs() in to one expression:
out = subs(out, {x,phi,lambda2,lambda4},{x1(1),x1(2),x1(3),x4(4)});
I am not certain, but I do not believe that fmincon can be applied to a symbolic expression. You may need to use matlabFunction to produce a function that fmincon can use from the expression.
  4 个评论
connie
connie 2011-1-21
equations were like:
beta_quote=atan(tan(beta)/((tan(alpha))^2+1));
theta=pi/2-beta_quote;
P2=(3*(cos(beta))^2-1)/2;
P4=(35*(cos(beta))^4-30*(cos(beta))^2+3)/8;
f_beta=exp(-(lamda2*P2+lamda4*P4));
A_p_1130=(alpha_c*(c*(sin(theta))^2*(sin(x))^2+a*(sin(phi)*cos(x)+cos(theta)*cos(phi)*sin(x))^2 ...
+b*(cos(phi)*cos(x)-cos(theta)*sin(phi)*sin(x))^2)^2+(1-alpha_c)*(-2*d*(sin(phi)*cos(x)...
+cos(theta)*cos(phi)*sin(x))*(cos(phi)*cos(x)-cos(theta)*sin(phi)*sin(x)))^2)*f_beta*sin(beta);
In your wrapper example: there are two x on the right side, are they different?
do I have to use both matlabFunction or anonymous function in that case? or I only need to choose one?
Walter Roberson
Walter Roberson 2011-1-25
wrapper = @(x) Generated(x,p,q,r)
makes wrapper a function handle designating a function that takes a single argument named x, whose result is calculated by calling Generated(x,p,q,r) where p, q, and r have the values that they had when the function handle was generated, and x is the value that was passed to the function call.
Your generated matlabFunction will almost certainly be a function in multiple variables, one for each undefined symbol. In order to call that generated function within fmincon you need to provide concrete values for each of those variables, but fmincon only provides a single argument to the user function it calls upon. The solution is to create a wrapper function that provides the values for all of the variables except the one being minimized.
Will you be trying to minimize the function over all four variables simultaneously? If so, then the wrapper function might look like,
wrapper = @(x) Generated(x(1),x(2),x(3),x(4));

请先登录,再进行评论。

更多回答(1 个)

Christopher Creutzig
1. About integration: after integration, I need to get a function that still has several unknown parameters. should I use symbolic integration "int()" or numeric integration "dblquad()" if the function expression is really complex?
If the result of integration contains free parameters, you cannot use numeric integration. Quadrature (i.e., numeric integration) can only return a number, and you may be able, depending on your problem, to get an approximation to the formula you are looking for by interpolating from numerical answers to parameter values, but numerical quadrature by itself will not be able to tell you that the result is something like 0.1234*sin(a)+5.6. Also note that quadrature is, necessarily, limited to definite integration.
What Walter said, is correct, though: The number of complicated formulas for which a symbolic integral exists (let alone having an algorithm/a computer program that can find them) is not all that big really.
  6 个评论
Walter Roberson
Walter Roberson 2011-1-25
What is a "formula integrable in finite terms" ? It is not uncommon for the integration of formulas involving rational constants to result in irrational numbers that we do not happen to have a finite name for.
Christopher Creutzig
At least for anything that comes anywhere close to Liouvillian field towers, the only constants required are algebraics, and we have names for them, as in sum(b*ln(...), b in RootOf(...)).
A “formula integrable in finite terms” is a formula f where there is, in the notation we use (the term obviously depends on that notation), a formula g such that g'=f. If such a g would require constants that cannot be represented, f is not integrable in finite terms.
But I'm not sure I see how to construct such an f, especially given that I'd happily accept finite-length descriptions involving infinite sums etc. for the constants, since they are part of the CAS vocabulary.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by