필터 지우기
필터 지우기

how to use lsqcurvefit on a function that contain a series

조회 수: 2 (최근 30일)
kiet ngo
kiet ngo 2024년 3월 19일
편집: Torsten 2024년 3월 20일
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

답변 (1개)

John D'Errico
John D'Errico 2024년 3월 19일
편집: John D'Errico 2024년 3월 19일
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
kiet ngo
kiet ngo 2024년 3월 20일
편집: kiet ngo 2024년 3월 20일
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 2024년 3월 20일
편집: Torsten 2024년 3월 20일
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.

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

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by