Adding Function Handles with "different" parameters and different factors?!

10 Ansichten (letzte 30 Tage)
Payjay
Payjay am 28 Jan. 2019
Kommentiert: Payjay am 28 Jan. 2019
Hi there,
I have smth. like this:
%some data i want to fit
xfit = somedata;
yfit = somedata;
% init handles?
summed_EOF1 = @(x) 0;
EOF1 = @(x) 0;
helperfun = @(x) 0;
for i = 1 : length(xfit)
%before it will be decided how many terms are used, e.g. 3
for j=length(number_of_terms):-1:1
if j == 1
helperfun = @(x) (helperfun(x) + abs(x(1)*xfit(i) + x(2)*yfit(i) + x(3))^x(4));
else
helperfun = @(x) (helperfun(x) + abs(x( j * 4 + 1)*xfit(i) + x(j * 4 + 2)*yfit(i) + x(j * 4 + 3))^x(j*4 + 4));
end
end
% error of fit function
EOF1 = @(x) (1 - (helperfun(x))^(1/5) )^2;
summed_EOF1 = @(x)( summed_EOF1(x) + EOF1(x));
end
in order to get a cost function, but I am not sure if this code really sums all terms adequately. When I minimize this cost function only the first 4 parameters are fitted and the rest remains at the initial guess.
Does someone know how to properly sum function handles?
Greets,
Pay
  4 Kommentare
Walter Roberson
Walter Roberson am 28 Jan. 2019
You do not need to. You know the number of variables ahead of time.
x = sym('x', 1, N)
Then index x as needed .
Be sure to matlabFunction() 'vars', {x}
so that it bundles all the entries into a vector when generating code.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by