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:
problem with parameter estimation

Subject: problem with parameter estimation

From: Marcio Barbalho

Date: 14 Jan, 2011 11:36:04

Message: 1 of 2

Dear friends...

I have been working on this project aimed at estimating parameters to predict the behaviour of a chemical reactor. I built 3 files, they work just file in MatLab but as I don't have Matlab yet, I'm trying to figure out a way of running it on scilab.

These are the files... Could anyone gently tell what's wrong here?? Of course, I should do some editing, but the question is: where?
_____________________________________________________________________
function val=L_Squares(k)
a=k(1);
b=k(2);
time = (0:6)';
% experimental data
y_exp(:,1) = [-1 2 11 26 47 74 107];
y_exp(:,2) = [ 1 3 09 19 33 51 73];
%
y0 = y_exp(1,:);
[t y_calc]=ode45('mymodel',time,y0,[],a,b);
resid = (y_calc - y_exp).*(y_calc - y_exp);
val = sum(sum(resid));
____________________________________________________________________
% optimization routine
clc
% format short g
tic
% starting guess
a = 0.1;
b = 0.4;
k=[a b];
options = optimset('TolFun',1e-2,'TolX',1e-2,'MaxFunEvals',1d6,'MaxIter',1d6);
[param L_Squares flag details]=fminsearch('L_Squares',k,options);
elapsed_time = toc;
parametros = param'
a = parametros(1); b = parametros(2);
save p a b
if flag == 1
     fprintf('Sistema convergiu!!!\n\n')
else
     fprintf('Sistema NAO convergiu!!!\n\n')
end
fprintf('Numero de iteracoes ---------------- %g \n',details.iterations)
fprintf('Soma dos quadrados ----------------- %g \n',L_Squares)
fprintf('Numero de chamadas do modelo ------- %g \n',details.funcCount)
fprintf('Algoritmo da minimizacao------------ %s \n',details.algorithm)
if elapsed_time < 60
fprintf('Tempo decorrido -------------------- %g s \n\n',elapsed_time)
else
fprintf('Tempo decorrido -------------------- %g min \n\n',elapsed_time)
end

y_exp(:,1) = [-1 2 11 26 47 74 107];
y_exp(:,2) = [ 1 3 09 19 33 51 73];

time = (0:6)';
[t,y] = ode45('templ',time,[-1 1]);
figure(34)
clf
plot(time,y_exp(:,1),'ok')
hold on
plot(time,y_exp(:,2),'ob')
plot(time,y(:,1),'-k')
plot(time,y(:,2),'-b')
_____________________________________________________________________
function dy = mymodel(t,y,flag,a,b)
dy(1) = -a*y(2) + y(1) + t^2 + 6*t + b;
dy(2) = b*y(1) - a*y(2) + 4*t + (a+b)*(1-t^2);
dy = dy';

Any help will be very much appreciated

Subject: problem with parameter estimation

From: Marcio Barbalho

Date: 14 Jan, 2011 13:10:05

Message: 2 of 2

This is the error message I get:

!--error 15
Submatrix incorrectly defined.

at line 8 of function called by :
at line 2 of function called by :
at line 59 of function optimbase_function called by :
at line 6 of function neldermead_costf called by :
at line 3 of function fun called by :
at line 6 of function optimsimplex_compsomefv called by :
at line 5 of function optimsimplex_computefv called by :
at line 50 of function optimsimplex_pfeffer called by :
at line 99 of function optimsimplex_new called by :
at line 31 of function neldermead_startup called by :
at line 8 of function neldermead_search called by :
at line 90 of function fminsearch called by :
[param hugL flag details]=fminsearch(LSquares,k,options);
at line 32 of exec file called by :
exec('Z:\saved\scilab\ode_par\L_Squares.sce', -1)

Thanks

Tags for this Thread

No tags are associated with 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