Solving Nonlinear Matrix Equation
1 view (last 30 days)
Show older comments
AAQIB PEERZADA
on 30 Nov 2021
Edited: Walter Roberson
on 30 Nov 2021
I have an equation of the form
where A= positive definite symmetrix matrix (2 by 2), X is data matrix of dimensions (N by 2) and mu is a vector (1 by 2). Ki are scaler values and P is a constant. I want to use fsolve to solve for mu.
I am using the script as below
K_values in the code is an array that contains the values of each Ki.
data in the code is a ( N by 2 ) matrix of values that is passed on to the script below
The matrix A is calculated before running the script. The only unknown is the vector mu.
fsolve returns an error: Not enough input arguments
Any insight into solving this is highly appreciated.
syms X [length(data) 2]
syms mu [1 2]
syms K
T=subs(trace(inv(A)*(X-mu)'*(X-mu))^(P),X,data);
L1=subs(K*T,{K},{[K_values]});
fun1=matlabFunction(sum(L1));
mu0=[1;1];
options = optimoptions('fsolve','Display','none');
mu=fsolve(fun1,mu0,options);
0 Comments
Accepted Answer
Walter Roberson
on 30 Nov 2021
fun1=matlabFunction(sum(L1));
That is going to produce a function with two inputs, mu1 and mu2. fsolve() only provides one input as a vector.
fun1=matlabFunction(sum(L1), 'vars', {mu} );
3 Comments
Walter Roberson
on 30 Nov 2021
Edited: Walter Roberson
on 30 Nov 2021
When I scan over the default algorithm at https://www.mathworks.com/help/optim/ug/equation-solving-algorithms.html#f51372 the use of the \ operator hints to me that your function needs to return a square matrix to solve the equations properly but I could be misreading.
The default algorithm was chosen because it was designed for nonlinear problems. However it is not always appropriate. To avoid seeing warning message, pass an options structure telling the code to use a different algorithm.
More Answers (0)
See Also
Categories
Find more on Particle & Nuclear Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!