Solving non linear equations
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I need to solve a non linear equation of this type:
F = mu - d1*M2*x + d2*M3*kron(x,x)
where everything is known but x (which is a vector 3x1, x=[x1,x2,x3], moreover it must always be that x1+x2+x3=1 and that 0<=xi<=1 for i=1,2,3).
Take into account that also in d1 and d2 the unknown vector x is present:
A; %it is a 154x3 matrix
sp=x'*cov(A)*x;
skp=x'*coskewness(A)*(kron(x,x)); %coskewness is a 3x9 matrix while kron is the %kronecker product
B=1+((L^2)/2)*sp+((L^3)/6)*skp; %this B enters in d1 and d2
mu = mean(A)'; %this is a 3x1 vector
L=10; %it is just a fixed parameter
d1 = L/B;
M2 = cov(A); %which is a 3x3 matrix
d2 = L*L/(2*B);
M3 = coskewness(A);
%where A is a known matrix 154x3.
I have already implemented a routine to solve this equation and here is the code. However I am not sure this is the best way to solve it. In fact, depending on how small I take abs(F), it gives very different results. Moreover it seems that for abs(F)<0.019 there are no results for k. I would like also to implement the same using the function "fsolve". I have tried but it seems it does not recognize the vector x.
%the unknown vector is x=[x1 x2 x3], it must always be that x1+x2+x3=1 and that 0<=xi<=1 for i=1,2,3
x1 = [0:0.001:1];
x2 = [0:0.001:1];
x3 = 1-x1-x2;
for (i=[1:length(x1)])
for (j=[1:length(x2)])
x3 = 1-x1(i)-x2(j);
if (x3 >=0)
F = opt([x1(i), x2(j), x3]',A);
if (abs(F) < 0.02)
k = [x1(i), x2(j), x3]
end
end
end
end
%some results I got
%for abs(F)<0.06, k=[0.78,0.11,0.11]
%for abs(F)<0.02, k=[0.31,0.53,0.16]
% for abs(F)<0.019, no results
THANK TO ANYBODY WILL BE SO KIND TO HELP ME. I APPRECIATE THAT.
Claudio
1 个评论
Walter Roberson
2012-11-27
You say that fsolve() does not recognize the vector x, but you do not have any x vector in the code you show. Please show the setup and fsolve() call and the routine that you are invoking with fsolve()
回答(1 个)
Babak
2012-11-27
YOu don't need to write your own nonlinear equation solver as MATLAB already has powerful built-in commands to do this, like fsolve, if you have the optimization toolbox.
Your set of equations are constrained with x1+x2+x3=1. MATLAB has commands to solve constrained equations, but if I were you, I would reduce the number of equations to two by replacing x3 = 1-x1-x2 in all equations then use the optimization toolbox like fsolve to solve the equations.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!