Nonlinear fit instead of setting up a non linear equation?

조회 수: 1 (최근 30일)
Samuele Bolotta
Samuele Bolotta 2021년 2월 16일
편집: Matt J 2021년 2월 19일
Hello everyone,
I'll attach my script here, in case you want to run the simulation yourself.
My task is to find two values x and y so that if I multiply them by G_max_chl2 and G_max_glu2 (two scalar values that I pre-defined in previous parts of the code) respectively, this:
CPSC_2 = ((G_max_chl2 * x) .* (1 - exp(-t / tau_rise_In2)) .* (exp(-t / tau_decay_In2)) * (Vm - EChl2)) + ((G_max_glu2 * y) .* (1 - exp(-t / tau_rise_Ex2)) .* exp(-t / tau_decay_Ex2) * (Vm - EGlu2))
becomes the same as this:
CPSC_1 = ((G_max_chl) .* (1 - exp(-t / tau_rise_In)) .* (exp(-t / tau_decay_In)) * (Vm - EChl)) + (G_max_glu .* (1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex) * (Vm - EGlu))
1 All the variables above are the same for the two equations, except for the four "G_max" values. The only two variables that change are G_max_chl2 and G_max_glu2, so that they become the same as G_max_chl and G_max_glu.
2 Some of these variables are matrices, but in this case they are not involved and should remain the same (only the two scalars G_max_chl2 and G_max_glu2 should change)
I solved the task setting up a nonlinear equation:
% This is the difference that has to be minimized
Diff_CPSC = abs((((G_max_chl2) .* ((1 - exp(-t / tau_rise_In2)) .* ...
(exp(-t / tau_decay_In2))) * (Vm - EChl2)) + ((G_max_glu2) .* ...
((1 - exp(-t / tau_rise_Ex2)) .* exp(-t / tau_decay_Ex2)) * (Vm - EGlu2))) - (((G_max_chl) .* ...
((1 - exp(-t / tau_rise_In)) .* exp(-t / tau_decay_In)) * ...
(Vm - EChl)) + ((G_max_glu) .* ((1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex)) * (Vm - EGlu))));
% EQUATION
% Create a nonlinear equation
x = optimvar('x',1);
y = optimvar('y',1);
% Define function to minimize
eq1 = (((G_max_chl2 * x) .* ((1 - exp(-t / tau_rise_In2)) .* ...
(exp(-t / tau_decay_In2))) * (Vm - EChl2)) + ((G_max_glu2 * y) .* ...
((1 - exp(-t / tau_rise_Ex2)) .* exp(-t / tau_decay_Ex2))* ...
(Vm - EGlu2))) == ((G_max_chl) .* ((1 - exp(-t / tau_rise_In)) .* ...
exp(-t / tau_decay_In)) * (Vm - EChl)) + ((G_max_glu) .* ...
((1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex)) * (Vm - EGlu));
% Create an equation problem, and place the equation in the problem
prob = eqnproblem;
prob.Equations.eq1 = eq1;
% Show the problem
show(prob);
% Specify the initial point as a structure
x0.x = G_max_chl / G_max_chl2;
x0.y = G_max_glu / G_max_glu2;
[sol,fval,exitflag] = solve(prob,x0);
% View the solution point and convert to double
disp(sol.x);
disp(sol.y);
x = sol.x;
y = sol.y;
However, I find this procedure a bit laborious because, if I wanted to optimize other variables, I'd have to hard code the unknown variables everytime. My question is:
  • This procedure forces me to know all of the values of CPSC_2, which in this case is true because I generated the simulation. However, if it were coming from experimental recordings, it wouldn't be the case anymore. Is there a way to fit a CPSC_2 (whose variables are unknown) to CPSC_1 (whose variables are known)?

채택된 답변

Matt J
Matt J 2021년 2월 16일
편집: Matt J 2021년 2월 16일
Your problem appears to be a linear fit. I see no non-linear dependence on x or y. You should therefore use lsqlin, if you also have bounds or linear constraints.
Otherwise, you could just use mldivide() or linsolve().
  댓글 수: 3
Samuele Bolotta
Samuele Bolotta 2021년 2월 19일
Hi Matt, sorry to bother you again. By using lsqlin, I end up:
a) Having more flexibility, because I don't have to specify to which parameters the unknown variables x or y or z should be coupled.
b) However, I lose information because I simply make matrix CPSC2 equal to CPSC, without being able to specify a cost function that I want to minimize (the difference between CPSC2 and CPSC) and without being able to trace back which parameters changed.
My supervisor says I should fit the matrix CPSC2 (whose underlying distribution is unknown, when it will come from experimental recordings) to the function that created CPSC:
((G_max_chl) .* (1 - exp(-t / tau_rise_In)) .* (exp(-t / tau_decay_In)) * (Vm - EChl)) + (G_max_glu .* (1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex) * (Vm - EGlu))
Does this (https://it.mathworks.com/help/curvefit/fit.html) seem a good candidate for that?
Thanks!
Matt J
Matt J 2021년 2월 19일
편집: Matt J 2021년 2월 19일
You could use fmincon if you want more control over the cost function,

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Econometrics Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by