×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Problem with fminsearch in Matlab

## Problem with fminsearch in Matlab

(OP)
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:)

### RE: Problem with fminsearch in Matlab

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!!

### RE: Problem with fminsearch in Matlab

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])

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!