Using fminsearch to determine variables
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Currently I am working on estimating two different variables of a sigmoid curve graph, the first variable 'z(1)' is the slope of the sigmoid curve and 'z(2)' is half of the maximum height of the curve. I currently have an equation that outputs y-values of the curve, "E" based on these variables and the input/x value of 'C1': E=C1.^z(1)./(z(2)^z(1)+C1.^z(1)
I need to use fminsearch to calculate the values of 'z(1)' and 'z(2)'.
For the function tag I created:
f=@(z)C1.^z(1)./(z(2)^z(1)+C1.^z(1))
and then typed out
params=fminsearch(f,[1, 0.55])
with 1 and 0.55 being my guesses for the approximate half maximum value, and the slope of the sigmoid curve, respectively.
When I run the function it outputs an error on the fminsearch line I created: 'Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 41-by-1.'
Any help with fixing this would be appreciated!
0 commentaires
Réponses (1)
Star Strider
le 15 Mar 2021
The fminsearch function (and all other optimization functions I know of) want a scalar result from the function they are optimising.
In this instance, I would use:
f=@(z,C1) C1.^z(1)./(z(2)^z(1)+C1.^z(1));
params=fminsearch(@(z) norm(y-f(z,C1)),[1, 0.55])
That should work. If it has problems, please post the entire error message (if it throws an error), or a reasonably detailed description of what it is not doing that you want it to do, or what it is doing that you do not want it to do.
3 commentaires
Star Strider
le 15 Mar 2021
I assume here that ‘z’ is the parameter vector, ‘y’ is the dependent variable and that ‘C1’ is the independent variable vector.
If that is not the situation, please define them so I can make appropriate changes to my code example.
Walter Roberson
le 15 Mar 2021
That is, in Star Strider's code, y stands for the vector of known output data values (must be a column vector) and C1 stands for the vector of known input data values (must be a column vector too)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!