function [J] = genetic_ode_function(x, t_truth, x_truth, x0) % % x is a matrix of size [ N_pop x N_vars ] % % Written by: % -- % John L. Weatherwax 2006-08-28 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- [ N_pop, N_vars ] = size(x); x_dim = size(x0,1); power_of_pointwise_error = 3.; % maybe a power > 1 would do a better job selecting optimal population members J = zeros(N_pop,1); for pi=1:N_pop, % From the sample x, extract the matrix A: % A = reshape( x(pi,:), [x_dim,x_dim] ); % Solve an ode with these coefficient matrices: [t_sample,x_sample] = ode45( @(t,x) linear_ode_function( x, A ), t_truth, x0 ); % compute the norm between the truth and what we found when we solved the ODE with our given A and b: J(pi) = mean( abs(x_sample(:) - x_truth(:)).^power_of_pointwise_error ); end