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
2020년 3월 11일
0 개 추천
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
Hao Mu
2020년 3월 11일
Walter Roberson
2020년 3월 11일
You thought you initialized them but you didn't.
Otherwise we need enough to be able to reproduce the problem... All initialization.
카테고리
도움말 센터 및 File Exchange에서 Particle Swarm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!