Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fsolve with 2 inputs

89 views
Skip to first unread message

Belinda Kellerer

unread,
May 18, 2017, 4:45:10 AM5/18/17
to
Hello,

I want to solve the following equation using fsolve:

fun = @(w)[w(1)-((max(1-sqrt(aa)/(sqrt((meanA-gwb*w(2))'*waTeil*(meanA-gwb*w(2)))),0))*waTeil*(meanA-gwb*w(2)));...
w(2)-((max(1-sqrt(ab)/(sqrt((meanB-hwa*w(1))'*wbTeil*(meanB-hwa*w(1)))),0))*wbTeil*(meanB-hwa*w(1)))];
x0WA = zeros(8,1);
x0WB = 0;
opt = optimset('Display','off');
weights = fsolve(fun,[x0WA; x0WB]);

where aa,ab, wbTeil are scalars
meanA, gwb are 8x1 vectors
hwa is a 1x8 vector
waTeil is a 8x8 matrix

Is it possible to solve the equation?

I get the following error:

Error using /
Matrix dimensions must agree.

Error in
AAparameterAndModelUncertainty>@(w)[w(1)-((max(1-sqrt(aa)/(sqrt((meanA-gwb*w(2))'*waTeil*(meanA-gwb*w(2)))),0))*waTeil*(meanA-gwb*w(2)));w(2)-((max(1-sqrt(ab)/(sqrt((meanB-hwa*w(1))'*wbTeil*(meanB-hwa*w(1)))),0))*wbTeil*(meanB-hwa*w(1)))]
(line 72)
w(2)-((max(1-sqrt(ab)/(sqrt((meanB-hwa*w(1))'*wbTeil*(meanB-hwa*w(1)))),0))*wbTeil2*(meanB-hwa*w(1)))];

Error in fsolve (line 230)
fuser = feval(funfcn{3},x,varargin{:});

Error in AAparameterAndModelUncertainty (line 76)
weights = fsolve(fun,[x0WA; x0WB]);

Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.

I made sure that the matrix dimensions agree, so I am wondering if the error is caused by the fact that w(1) is a vector and w(2) is a scalar.

Thanks for your help

Torsten

unread,
May 18, 2017, 5:21:07 AM5/18/17
to
"Belinda Kellerer" wrote in message <ofjmuh$dsh$1...@newscl01ah.mathworks.com>...
In fsolve, w(1) can never be a vector - it is a scalar. If you want "w(1)" to be a vector, you will have to use [w(1); w(2); w(3); w(4); w(5); w(6); w(7); w(8)] for your "w(1)" and w(9) for your w(2).

Best wishes
Torsten.

Belinda Kellerer

unread,
May 18, 2017, 5:32:08 AM5/18/17
to
Thank you very much, that worked.

Is there a possibility to have the numbers of elements in "w(1)" flexible? The number is not always 8, it varies.

Torsten

unread,
May 18, 2017, 5:45:08 AM5/18/17
to
"Belinda Kellerer" wrote in message <ofjpmj$jk1$1...@newscl01ah.mathworks.com>...
> Thank you very much, that worked.
>
> Is there a possibility to have the numbers of elements in "w(1)" flexible? The number is not always 8, it varies.

You can use w(i1:i2) or w(i1:i2).' where i1 and i2 are the positions in the solution vector where "w(1)" starts and ends.

Best wishes
Torsten.

Belinda Kellerer

unread,
May 18, 2017, 6:08:07 AM5/18/17
to
Yes, that worked. Thank you.
0 new messages