how to use lsqcurvefit on a function that contain a series

8 views (last 30 days)
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
clc
clear
close all
syms n x
%input data
xdata=420;
ydata=0.1;
%function
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

Answers (1)

John D'Errico
John D'Errico on 19 Mar 2024
Edited: John D'Errico on 19 Mar 2024
You only have ONE data point.
xdata=420;
ydata=0.1;
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
xdata=420;
ydata=0.1;
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 Comments
kiet ngo
kiet ngo on 20 Mar 2024
Edited: kiet ngo on 20 Mar 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
Torsten on 20 Mar 2024
Edited: Torsten on 20 Mar 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.

Sign in to comment.

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!