Nonlinear fit instead of setting up a non linear equation?

1 次查看(过去 30 天)
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!

请先登录,再进行评论。

更多回答(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