Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

this code is giving same values of x irrespective of change in the power of xdata in fun???i am changing power 0.5 to 0.9 no change in output??

1 view (last 30 days)
xdata =[10.^(-5) 10.^(-4) 10.^(-3) 10.^(-2) 10.^(-1) 1];
ydata=(0.2575./((xdata.^2)+(0.333.*xdata)+1));
fun=@(x)sum(x(1)./((x(2).*xdata.^1.5+x(3).*xdata.^0.5+1)- ydata).^2);
rng default % For reproducibility
nvars = 3;
LB = [0.2;0.2; 0.2];
UB = [5; 5; 5];
options = optimoptions('particleswarm','SwarmSize',50,'HybridFcn',@fmincon);
x = particleswarm(fun,nvars,LB,UB,options)

Answers (1)

John D'Errico
John D'Errico on 13 Apr 2018
The answer is always to think clearly about what you did. Look at the numbers.
xdata =[10.^(-5) 10.^(-4) 10.^(-3) 10.^(-2) 10.^(-1) 1];
ydata=(0.2575./((xdata.^2)+(0.333.*xdata)+1));
ydata =
0.2575 0.25749 0.25741 0.25662 0.24681 0.11037
So almost all of ydata is CONSTANT. All but one element was virtually the same identical value. So you are trying to fit a curve that has essentially only two pieces of information in it.
fun=@(x)sum(x(1)./((x(2).*xdata.^1.5+x(3).*xdata.^0.5+1)- ydata).^2);
Almost all of xdata are tiny numbers, then raising it to a power makes it even smaller. But as well, it becomes effectively unimportant in the computation. You won't see much difference if you use xdata.^1.5 or xdata.^2 in the fit.
I cannot show you exactly what happens, because I don't have that toolbox.

This question is closed.

Community Treasure Hunt

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

Start Hunting!