# fsolve error when I change the given matrix

1 visualización (últimos 30 días)
Quynh tran el 7 de Abr. de 2016
Editada: Walter Roberson el 8 de Abr. de 2016
I have my prolems like this:
function F=myfun(x)
F=[x(1)+a*x(2)+b*x(3)
x(1)+5*x(2)+4*x(3)
x(1)+2*x(2)+3*x(3)]
P=[1 5 2
3 4 7] %I want to keep this matrix to make easier when I change a and b
a=P(1,1), b=P(1,3)
x0=[0 0 0]
[x,fval,exitflag]=fsolve(@myfun,x0)
and the error is:
Attempt to execute SCRIPT a as a function:
D:\Tinhtraoluucongsuat\flie goc\opt - KG_3_current_constraint_3_7_2015\a.m
Error in myfun (line 2)
F=[x(1)+a*x(2)+b*x(3)
Error in fsolve (line 219)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Walter Roberson el 7 de Abr. de 2016
F=[x(1)+a*x(2)+b*x(3)
you have not defined a or b yet. MATLAB assumes they might be functions, and goes looking for them. It finds an a.m that you have sitting around, but it happens that a.m is a script rather than a function, so it fails trying to execute it as a function to get a value for "a".
In MATLAB, if you name a function without passing it any parameters, it is the same as if you had used (), so MATLAB is treating your line as if it had been written
F=[x(1)+a()*x(2)+b()*x(3)
I suggest that you move your lines
P=[1 5 2
3 4 7] %I want to keep this matrix to make easier when I change a and b
a=P(1,1), b=P(1,3)
to before you assign anything to F.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Quynh tran el 8 de Abr. de 2016
Thank you very much, I found may errors.

Iniciar sesión para comentar.

### Categorías

Más información sobre Multi-Object Trackers en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by