Problem with fsolve -- Failure in initial user-supplied objective function evaluation
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am not sure whether it is due to the problem fsolve cannot solve this equation:
f=[(log(1+2*d)/2*d)-q];
What I did was, first of all I made a m file like this:
function f=sr(d)
f=[(log(1+2*d)/2*d)-q];
I have a series of q values, so in my main function I wrote this:
D=zeros(184,1);
c0=[0 4];
for i=1:184;
q=Q(i,1);
D(i,1)=fsolve(@sr,c0);
end
where Q stores the values for q.
The I encountered error messages as below:
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> sr at 2
f=[(log(1+2*d)/2*d)-0.715667311];
Error in ==> fsolve at 248
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE
cannot continue.
Is there anything I did wrong? Or is there any way I can solve this equation?
Many thanks for helping hands in advance.
0 Commenti
Risposta accettata
Matt J
il 22 Lug 2014
Modificato: Matt J
il 22 Lug 2014
c0 should be a scalar. Since you only have 1 equation, you presumably only have 1 unknown. So, if d is a scalar, its initial guess c0 should be a scalar, too.
You also haven't passed q to sr() in any way. See here for ways to pass fixed parameters to obejctive functions,
0 Commenti
Più risposte (1)
Michael Haderlein
il 22 Lug 2014
Actually, I'm a bit puzzled why that specific error appears. However, a few questions arise:
(I): Why is there no input variable q in the function sr? It is used in the function. Did you maybe use global variables?
(II): Why do you use the [] brackets in sr?
(III): If you set d to a vector ([0 4] in your example), you most likely want to get sf(0) and sf(4)? Then you need to use element-wise operations in your function (.* instead of *).
(IV): If you really want to solve sr simultaneously from two different starting points, you will get two answers. Accordingly, D needs to have two columns.
Hope I could help you. Best regards,
Michael
Vedere anche
Categorie
Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!