solving equations with vector as the unknown variable

3 views (last 30 days)
I need to solve the following equation which includes products between vectors and matrix:
>> F=@(x)(((x'*E)*((((Etrasp*i_covrend*E)/(Etrasp*i_covrend*uno))-((Etrasp*i_covrend*uno)/(unotrasp*i_covrend*uno)))^(-1))*(((i_covrend*E)/(Etrasp*i_covrend*uno))-((i_covrend*uno)/(unotrasp*i_covrend*uno))))-x)
>> fsolve(F,0)
Error using * Inner matrix dimensions must agree.
Error in @(x)(((x'*E)*((((Etrasp*i_covrend*E)/(Etrasp*i_covrend*uno))-((Etrasp*i_covrend*uno)/(unotrasp*i_covrend*uno)))^(-1))*(((i_covrend*E)/(Etrasp*i_covrend*uno))-((i_covrend*uno)/(unotrasp*i_covrend*uno))))-x)
Error in fsolve (line 241) fuser = feval(funfcn{3},x,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
I know that x must be a (10*1) vector and i'm sure that the dimensions of vectors and Matrix are correct. I don't know which command should I use to solve this equation and return a vector

Accepted Answer

John D'Errico
John D'Errico on 28 Jan 2015
Edited: John D'Errico on 28 Jan 2015
"I know that x must be a (10*1) vector and i'm sure that the dimensions of vectors and Matrix are correct."
However, what you don't know is how to read the help for fsolve. How did you call fsolve?
>> fsolve(F,0)
So how does fsolve know that the unknown is a vector? What length vector? You told it only that the unknown is a SCALAR, essentially a vector of length 1. The starting value is 0, a scalar.
So while YOU know that the unknown is a vector of size 10x1, fsolve thinks it is a scalar unknown. You did tell it that after all.
Unless of course, you have the mind reading toolbox installed. Then you would type this on the command line:
set(0,'readMinds','on')
Sadly, I think that toolbox is still under beta test.
  7 Comments
Camilla Lincetto
Camilla Lincetto on 28 Jan 2015
I'm sorry, I have to solve the minimization of x'Vx subject to the sum of x equal to 0 and the equation reduced to ((x'*E)*((abbd)^(-1))*(ebgd))-x=0.
I tried with fmincon so:
>> Aeq1 = ones(1,10)
>> beq1 = 0
% on another script called mycon
>> function ceq = mycon(x)
>> ceq=((x'*E)*((abbd)^(-1))*(ebgd))-x
% abbd is a number, x'E a product (1*10)*(10*1) so becomes a number and ebgd is a vector (10*1)
>> x=fmincon(@(x)x'*cov_rend*x,0.00001*ones(10,1),[],[],Aeq1,beq1,[],[],@mycon)
Warning: The default trust-region-reflective algorithm does not solve problems with the constraints you have specified. FMINCON will use the active-set algorithm instead. For information on applicable algorithms, see Choosing the Algorithm in the documentation. > In fmincon at 500 Warning: Your current settings will run a different algorithm (interior-point) in a future release. > In fmincon at 505 Error using mycon Too many output arguments.
Error in fmincon (line 718) [ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Caused by: Failure in initial user-supplied nonlinear constraint function evaluation. FMINCON cannot continue.
I know that maybe the nonlinear constraint (@mycon) isn't true, but I don't understand how I can solve this minimization. I'm not familiar with matlab because in the past I have used other programs, but now my prof forced me to use it. Thank you for all.
John D'Errico
John D'Errico on 28 Jan 2015
The warning message merely tells you that you used the wrong algorithm.
The error message suggests you made a mistake in the constraint function. If you read the help for fmincon, it tells you that the constraint function MUST return both equality and an inequality constraint result. If no inequalities are involved, then return an empty array for that argument.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!