Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Solving for two unknowns in an equation using fminsearch

Subject: Solving for two unknowns in an equation using fminsearch

From: Suyash

Date: 7 Nov, 2012 23:13:14

Message: 1 of 2

The problem is to find the a optimal values of p and k so that the error term, E is lowerst.
The error is defined as a product of a function mplres, Ix and Y are the known vectors I pass in, and Th is a constant scalar I pass in with a function, while p and k are unknown.

function E=mplres(p,k,Ix,Y,Th)
E = sum((10*log10(k.*((10.^(Ix./10)).^p - (10^(Th/10))^p)-Y)).^2);
end


Now, when I use fminsearch as below, I get an error that I am not able to solve...

>> [p, k, fval]=fminsearch(@(p,k) mplres(p,k,data(:,2),data(:,1),11.4),0.3,1)
Error using @(p,k)mplres(p,k,data(:,2),data(:,1),11.4)
Not enough input arguments.

Error in fminsearch (line 191)
fv(:,1) = funfcn(x,varargin{:});


I am not sure what else do I need to specify for the script to run. I am not able to find any appropriate examples either...

What should I be doing?

Thanks,

S

Subject: Solving for two unknowns in an equation using fminsearch

From: Matt J

Date: 8 Nov, 2012 00:24:12

Message: 2 of 2

"Suyash" wrote in message <k7epua$pum$1@newscl01ah.mathworks.com>...
> The problem is to find the a optimal values of p and k so that the error term, E is lowerst.
> The error is defined as a product of a function mplres, Ix and Y are the known vectors I pass in, and Th is a constant scalar I pass in with a function, while p and k are unknown.
============

p and k should not be separate arguments to mplres. You should be writing your functions in terms of a single vector argument [p;k]

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us