data fitting to equation
이전 댓글 표시
I have data for time(t) and pressure (p).
I want to fit these data to equation

I have done simple calcualtion and fittings in matlab. plese suggest how to fit data.
댓글 수: 12
Bjorn Gustavsson
2021년 2월 24일
Your model-function doesn't make sense as written. If that is what you want, you at least should know that that sum does not trivially converge since the exponential factor is independent of n and therefore can be factored out of the sum. This leaves you with:
That sum does not converge. You must first fix that.
Sudhir Rai
2021년 2월 24일
Bjorn Gustavsson
2021년 2월 24일
Check the variation of the sum for upper limits from 2 to 50, and then from 1000 to 1010. Then think about what this means.
Walter Roberson
2021년 2월 24일
The sum of (-1)^n starting from n = 1 is:
- 0 if n is even
- -1 if n is odd
We still suspect that you did not write the equations properly, or else that C2 is somehow a function of n in a way that you did not show.
Sudhir Rai
2021년 2월 25일
Bjorn Gustavsson
2021년 2월 25일
No it's not.
See here for the first few partial sums for t = 1/C_2: [-e 0 -e 0 -e 0 -e 0]
What you've written is not any analytical solution to Fick's law. It is pretty clear you intended to write something else, and think you wrote something else.
Sudhir Rai
2021년 2월 25일
syms c_1 c_2 d t real
syms n integer
assumeAlso(t >= 0 & n >= 0)
p(t) = c_1/d * (1+2*symsum((-1)^n * exp(-c_2*n^2*t/d^2), n, 1, inf))
Could you confirm that your parameters are c_1, c_2, and d ? If so then you can reduce by one parameter,
syms C_1 C_2
p2 = subs(p, {c_1, c_2}, {C_1*d, C_2*d^2})
subs(p2(t), {C_1, C_2}, {1/2, 3})
char(ans)
Walter Roberson
2021년 2월 25일
It looks like
C_1 * (1+2*symsum((-1)^n * exp(-C_2*n^2*t), n, 1, inf))
is equal to
C_1 * JacobiTheta4(0, exp(-C_2*t))
Walter Roberson
2021년 2월 26일
What scale of values are you expecting for c_1, c_2, d ? And what range of values are you expecting for time?
Unless you are dealing with quite small c_2/d and quite small t, then for floating point purposes the sum can be truncated at a quite small number of terms, such as 4 (or possibly fewer.) (Too few terms can be deceptive for small enough c_2/d )
Sudhir Rai
2023년 1월 10일
Sudhir Rai
2023년 1월 10일
답변 (1개)
Just Manuel
2021년 2월 24일
Refer to this answer from Star Strider:
You can fit any function using simple least squares regression. Just formulate your function (i guess you have already done that) in matlab, then make a cost function (least squares) and use fminsearch to optimize parameters c1 and c2
P = @(c, t) ... % your function
cost = @(c) sum((P(c,t) - p).^2);
% guess initial parameters
c_guess = [1 1];
% use fminsearch
c = fminsearch(cost, guess);
Cheers
Manuel
댓글 수: 2
Sudhir Rai
2023년 1월 10일
Walter Roberson
2023년 1월 10일
Your code 2 1/2 years ago did not involve fmincon at all, so we cannot guess what your current code looks like.
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
