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

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

답변 (1개)

Walter Roberson
Walter Roberson 2020년 3월 11일
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

Thanks for the answer! I am sorry that I did not clarify, the global variables are initialized previously from raw data.
You thought you initialized them but you didn't.
Otherwise we need enough to be able to reproduce the problem... All initialization.

댓글을 달려면 로그인하십시오.

카테고리

질문:

2020년 3월 10일

댓글:

2020년 3월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by