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!
