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:
ODE parameter estimation

Subject: ODE parameter estimation

From: Marcio Barbalho

Date: 27 Feb, 2010 14:10:22

Message: 1 of 4

Dear friends...

Could you please help me out with this problem?

I am trying to couple an ODE solver to an optimization function like 'fminsearch' to perform a very simple ODE parameter estimation.

From
y1 = 3t^2 - 1
y2 = 1 + 2t^2
I built the model below. I am trying to learn how to solve this kind of problem:

m-file called mymodel.m
---------------------------------------------------------------------
function dy = mymodel(t,y,a,b)
dy(1) = -a*y(2) + y(1) + t^2 + 6*t + b;
dy(2) = b*y(1) - a*y(2) - (a+b)*(1-t^2);
----------------------------------------------------------------------

m-file called least_squares.m
----------------------------------------------------------------------
function val=least_squares(k)
a=k(1); b=k(2);
mytime=(0:6)';
mydata(:,1) = [-1 2 11 26 47 74 107];
mydata(:,2) = [ 1 3 09 19 33 51 73];
y0(1) = -1; y0(2) = 1;
[t ycalc]=ode45('mymodel',mytime,y0,a,b);
resid = (ycalc-mydata).*(ycalc-mydata);
val = sum(resid);
----------------------------------------------------------------------

m-file called main_code.m
---------------------------------------------------------------------
clc
a = 2; b = 3;
least_squares([a b])
format long e
k=[a b];
[k lest_squares]=fminsearch('least_squares',k)
---------------------------------------------------------------------


I just can't get it solved whatsoever, nor can I figure out a way of debugging it.
Any comment will be very much appreciated.
Thanks in advance

Marcio

Subject: ODE parameter estimation

From: Marcio Barbalho

Date: 27 Feb, 2010 20:24:04

Message: 2 of 4

Any ideas on how to solve this problem?

Could you point out what I am doing wrong?

Many thanks.

Subject: ODE parameter estimation

From: Yi Cao

Date: 27 Feb, 2010 23:56:04

Message: 3 of 4

The least_squares function has bugs, 1) the caller to ode45 and 2) the last line to return val. A modified version is as follows.

Yi
----------------------------------------------------
function val=least_squares(k)
a=k(1); b=k(2);
mytime=(0:6)';
mydata(:,1) = [-1 2 11 26 47 74 107];
mydata(:,2) = [ 1 3 09 19 33 51 73];
y0(1) = -1; y0(2) = 1;
modelfun=@(t,x)mymodel(t,x,a,b);
[t ycalc]=ode45(modelfun,mytime,y0);
resid = (ycalc-mydata).*(ycalc-mydata);
val = sum(sum(resid));
-------------------------------------------------------



"Marcio Barbalho" <marciobarbalho@yahoo.com> wrote in message <hmbv13$10c$1@fred.mathworks.com>...
> Any ideas on how to solve this problem?
>
> Could you point out what I am doing wrong?
>
> Many thanks.

Subject: ODE parameter estimation

From: Marcio Barbalho

Date: 28 Feb, 2010 00:47:03

Message: 4 of 4

Thank you very much.

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