Only you know if your code is correct. Other than correcting for syntax errors (I used the vectorize function on your ‘f’ function to correct for those, since it threw errors in that respect), and without any other reference, we have to assume that you coded it correctly.
When I ran this (corrected) version of your code:
a0 = 0;
x1 = -10:0.1:10;
a1 = 1.329438561310570e-05;
a2 = -0.002504562092133;
a3 = -0.036785455629072;
a4 = 0.056797862719813;
a5 = 2.624845095825030;
a6 = 30.072580030528270;
f=@(a0) min(((max((((30.*a0.*(x1.^4))+(20.*a1.*(x1.^3))+(12.*a2.*(x1.^2))+(6.*a3.*x1)+(2.*a4))./((1+((6.*a0.*(x1.^5))+(5.*a1.*(x1.^4))+(4.*a2.*(x1.^3))+(3.*a3.*(x1.^2))+(2.*a4.*(x1))+(a5)).^2)).^1.5)))-0.1)+(-0.1-(min((((30.*a0.*(x1.^4))+(20.*a1.*(x1.^3))+(12.*a2.*(x1.^2))+(6.*a3.*(x1))+(2.*a4))./((1+((6.*a0.*(x1.^5))+(5.*a1.*(x1.^4))+(4.*a2.*(x1.^3))+(3.*a3.*(x1.^2))+(2.*a4.*(x1))+(a5)).^2)).^1.5)))));
a0_min = fminsearch(f,0)
I got this result:
a0_min =
7.879638671875000e-05
I do not understand your using the min and max functions in ‘f’, since that may not actually give you the correct parameter estimate for ‘a0’.
Removing the min and max calls:
f=@(a0) (((((((30.*a0.*(x1.^4))+(20.*a1.*(x1.^3))+(12.*a2.*(x1.^2))+(6.*a3.*x1)+(2.*a4))./((1+((6.*a0.*(x1.^5))+(5.*a1.*(x1.^4))+(4.*a2.*(x1.^3))+(3.*a3.*(x1.^2))+(2.*a4.*(x1))+(a5)).^2)).^1.5)))-0.1)+(-0.1-(min((((30.*a0.*(x1.^4))+(20.*a1.*(x1.^3))+(12.*a2.*(x1.^2))+(6.*a3.*(x1))+(2.*a4))./((1+((6.*a0.*(x1.^5))+(5.*a1.*(x1.^4))+(4.*a2.*(x1.^3))+(3.*a3.*(x1.^2))+(2.*a4.*(x1))+(a5)).^2)).^1.5)))));
and using:
a0_min = fminsearch(@(a0)norm(f(a0)),0)
the result is:
a0_min =
9.423828125000000e-05
If this is not what you expect, check your code for errors, correct any that you find, and run it again.
Best Answer