Error using symengine in numerical solver
Show older comments
Hi guys
Im trying to calculate the Worst Case Expected returns according to Tüntücu and König (2004). In order to derive the robust weights, I need to solve an equation numerically. Below is the code for the calculation of the weights.
syms w_r
S = vpasolve(0==(1-((length(r_dc_s)^(-0.5))*(chi2inv(0.95,length(mu))))...
/(1*sqrt(w_r'*V*w_r)+((length(r_dc_s)^(-0.5))*(chi2inv(0.95,length(mu))))))...
*w1+w2-w_r,w_r);
w_r would be the robust weights in a vector of Nx1. When I run the code, I always get the following error message:
Error using symengine
Invalid operands.
Error in sym/privBinaryOp (line 1032)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in / (line 375)
X = privBinaryOp(A, B, 'symobj::mrdivide');
If I understand the error message correctly, I would have to use element-wise multiplication or division. I do not see though where this would make sense. It can be seen that only the first line of the equation would result in a 1x1 double object, so would the second. The third line contains only Nx1 vectors (w1 and w2 are the speculative and minimal weights). The only place where I can imagine it could make sense to perform a element-wise multiplication would be .*w1+w2-w_r. This leads to the same error message though..
Do you guys can help me out with this? Would be highly appreciated!
Thanks in advance,
David
Accepted Answer
More Answers (1)
Devineni Aslesha
on 27 Mar 2020
0 votes
Hi David,
The above issue is replicated by assuming that ‘V’ is also a NX1 vector. The issue can be solved by using ‘./’ instead of ‘/’ in the vpasolve expression.
Here is a similar question for your information.
4 Comments
David Keller
on 27 Mar 2020
Devineni Aslesha
on 28 Mar 2020
Hi David
In the question, it is observed that vpasolve equation is a N*N array by considering V as an N*N matrix. This can be noticed by running the below code in which expr is an N*N array. vpasolve supports more equations than variables only for polynomial systems. For nonpolynomial equations, there is no general method of finding all solutions and vpasolve returns only one solution by default as mentioned in the doc link.
syms w_r
expr = (1-((length(r_dc_s)^(-0.5))*(chi2inv(0.95,length(mu))))...
./(1*sqrt(w_r'*V*w_r)+((length(r_dc_s)^(-0.5))*(chi2inv(0.95,length(mu))))))...
.*w1+w2-w_r;
Walter Roberson
on 28 Mar 2020
vpasolve() simply does not support having more equations than variables for non-polynomial systems. vpasolve() uses modified newton for nonlinear cases, and that method only works for square systems (same number of equations and variables.)
David Keller
on 28 Mar 2020
Categories
Find more on Systems of Nonlinear Equations 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!