figure% odefit.m SCRIPT
%USES LEASQR1 AND new ODE45k,XPRIME TO FIT PARAM IN ODES (STATS ASSIG 4A)
%

%Arthur Jutan 
%Dept of Chemical and Biochemical Enginering
%Univ of Western Ontario
%London Ontario Canada, N6A 5B9

%need to declare some param global

global  x0_ 

% DATA points
t=[0 10 20 40 80 160 320]';
yd=[0 .19 .14 .42 .42 .41 .27]';
yd1=[0 .14 .24 .3 .4 .46 .22]';
% take ave of y data
yd=(yd+yd1).*0.5;
% Initial Conditions for odes
x0_=[1 0]';
% Initial parameter guess
disp(' enter two values for parms k1 k2')
k=[.004 .003]'
 %k=readv(2);
% sub model is 'modode' here--- it in turn calls new ode45k which uses 'xprime(t,x,k)'
[f,p,var,iter,cor,std]=leasqr1(t,yd,k,'modode');
figure
plot(t,f,t,yd,'o')
grid
xlabel('time t');ylabel('y or x2')
title('fitted - , vs data o')
