fminsearch with 3 variables problem: one variable does not change during optimization.

2 visualizaciones (últimos 30 días)
Hello,
I am fitting a 3-element Windkessel model to some blood flow data (analog circuit shown below). The flow Q and pressure P are given, and I need to find Windkessel parameters R1, R2, and C.
My code minimizes the error between the fitted data and original data P using fminsearch. One of my variables, R1, does not change at all while two other variables are far away from the given answer. Does anyone know what is wrong with the code? Thank you very much!
% Global variables pressure, time, Q, p0, dqdt were initialized from raw data
% R1, R2, and C were estimated and not shown here.
theta = [R1 R2 C]; % R1 never changed before and after fitting.
[y,~] = fminsearch(@opt3_4W,theta);
function R = opt3_4W(theta)
global pressure time Q p0 dqdt
% Q is flow; p0 is initial pressure; dqdt is the first derivative of flow over time.
[t,p] = ode45(@(t,p) ode_3E_4W(t,p,time,Q,theta, dqdt) ,time,p0);
R = sum(abs((pressure-p).^2));
end
function dpdt = ode_3E_4W(t,p,time,flow,theta,dqdt)
q = interp1(time,flow,t);
dq = interp1(time,dqdt,t);
R1 = theta(1);
R2 = theta(2);
C = theta(3);
dpdt = q/C + (q*R1)/(R2*C) + R1*dq - p/(C*R2);
end

Respuestas (1)

Walter Roberson
Walter Roberson el 11 de Mzo. de 2020
Your global variables are not initialized so they are []. Your function is going to output empty or possibly 0.
Moral of the story: don't use global variables.
  2 comentarios
Hao Mu
Hao Mu el 11 de Mzo. de 2020
Thanks for the answer! I am sorry that I did not clarify, the global variables are initialized previously from raw data.
Walter Roberson
Walter Roberson el 11 de Mzo. de 2020
You thought you initialized them but you didn't.
Otherwise we need enough to be able to reproduce the problem... All initialization.

Iniciar sesión para comentar.

Categorías

Más información sobre Optimization en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by