How to use fminsearch for a vector
Show older comments
I am trying to write to code to deconvolute a complex function into a linear combination of trigonometric basis functions using fminsearch:
x = -pi:0.1:pi
y_sin=sin(x)
y_cos=cos(x)
y_tan=0.1*tan(x)
% define the variables
convol_spec=y_sin+2*y_cos+3*y_tan
%define the convoluted function
fun = @(coeff) (coeff(1)*y_sin) + (coeff(2)*y_cos) + (coeff(3)*y_tan) - convol_spec;
% define the objective function to search for "coeff" such that each trigonometric function will be multiplied by a coefficent "coeff"
coeff_guess= [0.33,0.33,0.33];
%guesses for the coefficents are all equally weighted
coeff = fminsearch(fun,coeff_guess)
%minimize the function using fminsearch with desired guesses for the coefficents
I get the following error "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-63." I suspect that this is becasue my tirgonometirc basis functions are 1x63 vectors and not scalers. Every example I have found uses scalers. Is it possible to use fminsearch for such sclaers? Thanks.
Accepted Answer
More Answers (0)
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!