Using a symsum inside a fsolve

I need to estimate the parameters of a model using the equations of the attached image. From my readings of the matlab documentation I would have to use fsolve to solve that system of non-linear equations, but there is a sum of multiple terms inside the equations. If I understood correctly, I would have to run a Symsum "nested" inside the fsolve. Is that correct? How do I implement this? Any advice is appreciated.

1 Commento

VBBV
VBBV il 2 Ago 2023

No, you can run symsum separately for the summation terms only. Nested symsum inside a loop may not be necessary.

Accedi per commentare.

Risposte (1)

Torsten
Torsten il 2 Ago 2023
Modificato: Torsten il 2 Ago 2023

0 voti

If I understood correctly, I would have to run a Symsum "nested" inside the fsolve. Is that correct? How do I implement this?
No, it's not correct. You can either use a for loop to add the terms one by one or use MATLAB's "sum". "symsum" is inadequate because there are no symbolic variables if you use "fsolve".

11 Commenti

Thank you for your quick answer. I was thinking the same thing. Now that I have the experiemental data, I can start testing some codes. The reason I think the for loop will not work is because I need to find the optimized parameters of a model, and those unkown parameters are present in the sum. The image bellow is from the paper I am basing myself to estimate those parameters. β, λ and q are the parameters I am trying to estimate. X is the variable that I have experimentally recorded. According to the paper, I need to equate these equations to zero and then solve this system of equations. Since they are non-linear, we cant get their closed forms and need to use an optmizer to find their minimum. I am having some issues figuring out how to implement this in matlab, since I am not an experienced programmer.
If you have any advice on how to do it, it would be greatly appreciated. Once again, thanks for the response.
Torsten
Torsten il 5 Ago 2023
Modificato: Torsten il 5 Ago 2023
Is this a log-likelihood estimate of the parameters q, beta and lambda of some distribution ? Could the name the distribution and its pdf ?
Indeed it is. It is a q-weibull distribution and its pdf is:
If I understood correctly (I am a biologist and math is not my strongest suit by far), it is a generalization of the weibull distribution that seems to work pretty well with a lot of data with long range correlations. I want to test it on my data, but the estimation of the parameters is proving to be more challenging then expected.
Use "mle":
Look at the example "Fit Custom Probability Density Function" to see how to proceed.
x in the example is your data vector. Instead of v and d, you have q, beta and lambda as parameters.
And instead of ncx2rnd, you have your f from above.
I tryed implementing mle. It seems to be what I am looking for, but the following error happened:
Any ideia what might be causing this? Again, I appreciate the time and effort you have dedicated to helping me. Thank you!
We need your code and possibly your data in order to reproduce the error.
Please include as plain ascii and not as graphics.
Torsten
Torsten il 10 Ago 2023
I cannot tell if it makes sense what you are doing. Usually, one directly takes the raw data to fit the distribution to without preprocessing them as you do.
Leonardo Peixoto
Leonardo Peixoto il 10 Ago 2023
Modificato: Leonardo Peixoto il 10 Ago 2023
My code can be seen bellow. I tryed commenting on it as much as could to explain my reasoning in every step. I`ll have to ask my coworkers for permission before sharing the data. In the code, the parameter q, beta and lambda are represented by q,b,l.
% Function to estimate the q-weibull parameters.
% Inputs are:
% MEEP_Intervals: A numeric matrix containing all MEEP intervals on all
% 78 recordings. The colors of the cells on line 2 of the original excel
% file represent the different calcium concentrations.
% concentrations: A 2x7 matrix with the columns of MEEP_Intervals in which the
% different concentrations start and finish. The columns represent the
% different calcium concentrations and the lines contain the start and finish
% columns in MEEP_Intervals of the respective concentration of calcium.
% Outputs:
% parametersPerConcentration: 3x7 matrix with the parameters q,beta and
% lambda, respectively, for each of the seven calcium concentrations.
% times: Estructure containing the values of the MEEP intervals bins in each
% concentration. Each bin is represented by its righ edge value.
% y: Normalized bin counts.
% parametersCIs: Estructure with the confidence intervals of each parameter
% for each concentration.
function [parametersPerConcentration,parametersCIs,times,y]=Qweibullparameters(MEEP_Intervals,concentrations)
parametersPerConcentration = [];
for i =1:size(concentrations,2)
% Concatenating the MEEP intervals of a given calcium concentration in a
% single vector
M = [];
for a=concentrations(1,i):concentrations(2,i)
M = [M,MEEP_Intervals(:,a)'];
end
% Using matlab`s algorithm to calculate bin width and bin counts
[N,edges] = histcounts(M);
% creating the times vector with the right edges of the bins
times.(['concentration',num2str(i)]) =edges(1,2:end);
% creating the normalized bin counts
y.(['concentration', num2str(i)]) = N./sum(N);
% creating the x vector for the mle function
x = times.(['concentration',num2str(i)]);
% Using the maximum likelehood estimates function to estimate parameters
% with a custom pdf
[phat,pci] = mle(x,'pdf',@(x,q,b,l)(2-q)*b*l*x.^(b-1).*(1-(1-q)*l*x.^b).^(1/(1-q)),'Start',[0.5,0.5,0.5]);
% Storing the parameters estimates.
parametersPerConcentration = [parametersPerConcentration,phat'];
% Storing the parameters confidence intervals
parametersCIs.(['concentration',num2str(i)])=pci;
end
end
Honestly, that is what I first thought of doing. The reason I am trying to do this preprocessing is because the papers I am basing myself seem to list it as important steps, and since I am a biologist with a much weaker math background than the authors, I decided to not take my chances and follow it. Maybe they put it there because the papers are about statistics and physics, and perhaps in those fields showing the math behind every step is relevant. I will try to simply fit the distribution to the data and see what happens. Once again, I am grateful for your help and I apologise for any incovenience.
Torsten
Torsten il 10 Ago 2023
Maybe you could give a link to the paper you are concerned with so that I know what you are trying to do.
Absolutely! The paper I was following initially was this one (https://drive.google.com/file/d/1t5dy3bS_JNDrDye5DH3JNXOMzDbCMhvR/view?usp=drive_link). I found the math a bit confusing and decided to follow this one (https://drive.google.com/file/d/1gUmHCMVZXEBcSW9zEjT8N4tAOAsnjYkg/view?usp=drive_link). Any insight would be greatly appreciated.

Accedi per commentare.

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Prodotti

Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by