Need help with least squares fit (lsqonlin)
Show older comments
This should be an easy one for someone I am a matlab newbie (have been for about a year now!) working with pre-existing code. The code was a genetic algorithm that found a bunch of parameters for me, and now I need to see how closely it fits data that I already have without re-running the whole thing, with the ability to manually change some of the parameters(for a sensitivity analysis)
The equations are in a file called WTTNF.m
function dy = WTTNF(~,y,par)
dy = zeros(4,1);
dy(1) = par.alpha*y(1)*(1-y(1)/y(4))-par.beta*y(1)-par.gamma*y(3)*y(1);
dy(2) = par.beta*y(1)+par.zeta*par.gamma*y(3)*y(1)-par.delta*y(2);
dy(3) = par.theta*y(2)+par.epsilon;
dy(4) = par.eta_c*y(3)*y(1)+par.eta_h*y(3)-par.psi*y(4)*(y(4)/par.Ko)^2;
The parameters are stored in par , as par.alpha, par.beta, etc.
The data is stored in a data , with time values and four sets of data points as follows:
>> data.t
ans =
0 1 2 3 6 8
>>data.val
ans =
132 183 358 448 563 526
246 312 741 665 996 1126
193 258 267 295 478 676
185 207 489 574 758 292
Now, this function (WTTNF) works fine within the context of a much larger and more complicated (GA) genetic algorithm. At the end of the GA, it spits out a fitness value, but now I want to start manually messing with some of the parameters (for a sensitivity analysis) and see what fitness value I get, without running the whole GA again. Should be simple
My best guess was to do this,
>> lsqonlin(WTTNF,data)
??? Input argument "par" is undefined.
Error in ==> WTTNF at 7 dy(1) = par.alpha*y(1)*(1-y(1)/y(4))-par.beta*y(1)-par.gamma*y(3)*y(1);
At the time I run this, I do have par in memory with all its associated values for each parameter.
To see what I mean, I can type:
>> par
par =
alpha: 0.1000
beta: 0.0437
gamma: 0.0273
zeta: 0.4935
delta: 6.2036
eta_h: 6.6211
eta_c: 0.0150
theta: 0.0235
epsilon: 5.0568
psi: 0.0243
Ko: 400
>> par.alpha
ans =
0.1000
>> par.beta
ans =
0.0437
This is probably something simple. Thanks for any help.
Regards
-Dave K
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics 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!