Borrar filtros
Borrar filtros

how to use lsqcurvefit on a function that contain a series

2 visualizaciones (últimos 30 días)
kiet ngo
kiet ngo el 19 de Mzo. de 2024
Editada: Torsten el 20 de Mzo. de 2024
Dear Sir/Madam, i want to find the adjustable parameter "a" of this function that contain a series using lsqcurvefit in matlab
This is my code but when i try to run the code, matlab show these error
close all
syms n x
%input data
fun =@(x,xdata) 1-0.608*symsum((1/(n^2))*exp(x(1)*n^2*xdata*246250),n,1,1000);
x0 = [1,1];
x = lsqcurvefit(fun,x0,xdata,ydata);
I would really appreciate the help
Best regards

Respuestas (1)

John D'Errico
John D'Errico el 19 de Mzo. de 2024
Editada: John D'Errico el 19 de Mzo. de 2024
You only have ONE data point.
So only ONE piece of information! How do you intend to estimate TWO parameters anyway?
x0 = [1,1];
Yes, you say that you only want to estimate one parameter. But you are telling lsqcurvefit that there are TWO parameters.
Next, symsum does NOT create a numerical value, thus a double. It creates at best, a SYMBOLIC parameter. You need to convert that to a double.
help double
Next, a must be a negative number, else that series will never converge. It will be a divergent series. So starting the estimation out with a POSITIVE starting value for a will cause the optimization to fail.
Anyway, since you have only one data point, you can just use solve, or actually, vpasolve, since this series is unlikely to have a symbolic solution.
syms n a
fun = 1-0.608*symsum((1/(n^2))*exp(a*n^2*xdata*246250),n,1,1000)
vpasolve(fun == 0,a)
As you can see, there was no need to use lsqcurvefit.
A fear however, is that as I said, it gives me a positive value for a. That means the series will not in fact converge at all. And THAT means if I use a different number of terms in the symsum, I will get a dramatically different solution.
fun = 1-0.608*symsum((1/(n^2))*exp(a*n^2*xdata*246250),n,1,2000)
vpasolve(fun == 0,a)
Do you see the prediction changed?
I'm sorry, but this suggests there is no solution. So, CAN we push the solver into finding a solution for negative values of a? I'll change the series expression in a subtle way. In fact, if you try various negative values for a there, I cannot get the solver to find any negative value for a that solves the probem, but since the series is truly, factually divergent for positive a, again, there is no solution.
  2 comentarios
kiet ngo
kiet ngo el 20 de Mzo. de 2024
Editada: kiet ngo el 20 de Mzo. de 2024
Thank you sir, i have been stucked on this problem for the last few days, also a must be a positive number so i'm afraid this equation indeed has no solution
Torsten el 20 de Mzo. de 2024
Editada: Torsten el 20 de Mzo. de 2024
As explained by @John D'Errico : for "a" being a positive number, your complete problem makes no sense since the infinite sum is infinity for every a > 0.

Iniciar sesión para comentar.


Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.





Community Treasure Hunt

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

Start Hunting!

Translated by