Is there anyway to solve a set of equations using fmincon instead of fsolve?

20 views (last 30 days)
Hi I want to find a value for a1,a2,a3,alpha,beta using these two equations by assuming adequate number of values for t1 and t3, also find the relevant amount of t2 in each of these assumptions.
a1*cos(t1+alpha)+a2*cos(t2)=1+a3*cos(t3+beta)
a1*sin(t1+alpha)+a2*sin(t2)=a3*sin(t3+beta)
1st I want to solve this using fmincon (not fsolve)
2nd I guess that adequate number of assumptions for t1 and t3 are 5 times; so we will have 5*2=10 equations while we have ten variables (including a1,a2,a3,alpha,beta + five times t2)
  4 Comments
Mehdi Ansarey
Mehdi Ansarey on 25 Oct 2012
Since fmincon searches for min of a scalar function with vector argument, So you should define a scalar objective function which it's minimum corresponding to solution of specified equation. for example:
function y= F(a1, a2, a3, alpha, beta)
y= (Error Of Eq1)+ (Error Of Eq2)
end
in above formule, Error must defined as appropriate function of your equation, i.e rms, square, abs, etc. Also because you have some set of parameters (t1, t3), each error must calculated for all parametersove formula and corresponding t2 parameter viewed as an extra unknown beside a1, a2, etc.
Yaser
Yaser on 26 Oct 2012
Matt, Sean; I have to some constraints for values of a1 a2 a3; they should be positive and more than 0.5. That's why I should use fmincon. Do you guys have any solution for this?

Sign in to comment.

Answers (2)

Matt J
Matt J on 25 Oct 2012
Edited: Matt J on 25 Oct 2012
Note that your equations become linear after an appropriate change of variables, so you might not even need an iterative solver at all
%new variables
A=a1*cos(alpha);
B=a1*sin(alpha);
C=a3*cos(beta);
D=a3*sin(beta);
%new equations
A*cos(t1)-B*sin(t1) + a2*cos(t2) = 1+C*cos(t3)-D*sin(t3)
A*sin(t1)+B*cos(t1) + a2*sin(t2) = C*sin(t3)+D*cos(t3)
It depends of course on what constraints are present, if any, but even then, lsqlin might be more appropriate for you than fmincon.
  2 Comments
Yaser
Yaser on 25 Oct 2012
thanks Matt
yur answer sounds logic just to simplify the problem. but the real problem that I have is that, what should be minimized here?!
in fact assuming the syntax to be: x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
and assuming that when t1=0.1:0.1:0.5 the corresponding t3 is t3=0.2:0.15:0.8
so what will be my fun, A, b, Aeq, beq, nonlcon?
Matt J
Matt J on 25 Oct 2012
Edited: Matt J on 25 Oct 2012
Well when you have an equation of the form F(X)=0 to solve where, as in your case, F() is vector-valued, you usually want to minimize
fun(X) = norm(F(X))^2.
The idea is to push norm(F(X)) as close as possible to zero.
As for the other stuff (A, b, Aeq, beq, and nonlcon), you haven't given enough information for anyone to know what those are in your particular case. You haven't mentioned any constraints on your unknowns.

Sign in to comment.


Matt J
Matt J on 26 Oct 2012
Edited: Matt J on 26 Oct 2012
Now that you've described your constraints, LSQNONLIN looks the most appropriate. It's like FSOLVE, but allows upper and lower bound constraints.

Community Treasure Hunt

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

Start Hunting!