Using fminsearch to determine variables

조회 수: 2 (최근 30일)
Jordan Rosales
Jordan Rosales 2021년 3월 14일
댓글: Walter Roberson 2021년 3월 15일
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!

답변 (1개)

Star Strider
Star Strider 2021년 3월 15일
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
Star Strider
Star Strider 2021년 3월 15일
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
Walter Roberson 2021년 3월 15일
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)

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by