Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with fminsearch in Matlab

Status
Not open for further replies.

575

Computer
Joined
Aug 17, 2007
Messages
1
Location
NO
want to solve the following problem
Function:
function [f] = nyfil(x)
v=ones(50,1);
v=v*10;
B_t=v;
S_t=v;
M_t = min(B_t,S_t)+max(B_t,S_t)/2;
x_s = x(2)/(x(5)+x(2));
x_b = x(1)/(x(5)+x(1));

f= sum(x(1)-x(2)+M_t*(log(x_b)+log(x_s))) + S_t*log(x(5)+x(2)) + sum(log(x(4)*(1-x(3))*exp(-x(5))*x_s^(S_t-M_t) +
x(4)*x(3)*exp(-x(5))*x_b^(B_t-M_t)*x_s^(S_t-M_t)*x_b^(B_t-M_t)));
%x(1) = epsilon_b
%x(2) = epsilon_s
%x(3) = delta
%x(4) = alpha
%x(5) = mu_
__________________________________________
I call this function from matlabs command window:
[x,fval] = fminsearch(@nyfil,[1,1,1,1,1])

I get the following error messages:
??? Error: File: Nyfil.m Line: 12 Column: 115
Incomplete or misformed expression or statement.

Error in ==> fminsearch at 175
fv(:,1) = funfcn(x,varargin{:});
_____________________________________
I dont understand why this expression is misformed or incomplete?

I try to solve the problem by starting with a small equation and then expanding it. Works with 2 variables in x but when I expand the equation f I get this error message. I would really appreciate if anyone could help me:)
 
if you have your m-file written just like you post it.. the problem is that the expresion is too long! you should use the operator ... to continue the ecuation at the next line.

hope it helps!!
 
Previous post isn't the cause. When I convert your function to single value instead of parms 50x1, I get:

x =
1.1815 1.2226e-015 1.0343 1.1537 1.5154
fval =
-347.66

%====================================================
function [f] = nyfil(x)
v=10;
B_t=v;
S_t=v;
M_t = min(B_t,S_t)+max(B_t,S_t)/2;
x_s = x(2)/(x(5)+x(2));
x_b = x(1)/(x(5)+x(1));

f= sum(x(1)-x(2)+M_t*(log(x_b)+log(x_s))) + S_t*log(x(5)+x(2)) + sum(log(x(4)*(1-x(3))*exp(-x(5))*x_s^(S_t-M_t) + x(4)*x(3)*exp(-x(5))*x_b^(B_t-M_t)*x_s^(S_t-M_t)*x_b^(B_t-M_t)));


called by:

[x,fval] = fminsearch(@nyfil,[1,1,1,1,1])
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top