How to calculate dx/dt in Matlab

조회 수: 78 (최근 30일)
Sami
Sami 2022년 8월 8일
댓글: Torsten 2022년 8월 10일
I have the following equation , where DOT is a vector [50;51....99], DOT^* is a constant = 100, Time has the same length as DOT
I know th symbolic solution which is for that:
But I need to get Kla value numerically, how do I do that in Matlab, I tried
kla = (gradient(DOT) ) ./ (gradient(Time) .* (DOT_star - DOT));
but I get very different answer from the analytical one. Any Idea what can be wrong in my equation ?
  댓글 수: 12
Sami
Sami 2022년 8월 10일
I do have two column matrix (DOT, TIME) with equadistant time, still the answer is wong,
I put here some values:
Time = [
15.5189990000000 15.5194990000000 15.5199990000000 15.5204990000000 15.5209990000000 15.5214990000000 15.5219990000000 15.5224990000000 15.5229990000000 15.5234990000000 15.5239990000000 15.5244990000000 15.5249990000000 15.5254990000000 15.5259990000000 15.5264990000000 15.5269990000000 15.5274990000000 15.5279990000000 15.5284990000000 15.5289990000000 15.5294990000000 15.5299990000000 15.5304990000000 15.5309990000000 15.5314990000000 15.5319990000000 15.5324990000000 15.5329990000000 15.5334990000000 15.5339990000000 15.5344990000000 15.5349990000000 15.5354990000000 15.5359990000000 15.5364990000000 15.5369990000000 15.5374990000000 15.5379990000000 15.5384990000000 15.5389990000000 15.5394990000000 15.5399990000000 15.5404990000000 15.5409990000000 15.5414990000000 15.5419990000000]
DOT = [86.2934346288157 88.3330265127609 88.5384902983721 86.2715655041141 86.2499514074551 87.9439995156669 93.3559053355719 100.588355429879 105.134156185296 105.998293130410 101.914607317850 97.2442257193124 96.1705619186325 97.6457751783728 102.639322947358 106.338201652074 103.282744164835 99.3874791803122 98.3360407005509 98.1827495464303 98.4462091917985 98.4677691127529 98.6027332770350 99.3776569743805 101.164673911659 102.507302979436 101.756315732742 100.862114099507 100.796601964307 100.746832837656 100.715064263002 100.703558708876 100.714578643816 100.750386536354 100.813244855022 100.905416068358 101.029162644892 101.186747053159 101.341304721314 101.205048020864 100.712709159760 100.334695799161 100.192106610432 100.121980159814 100.129391137103 100.219415163613 100.329039499815]
Dot_star = 100;
I get different Kla for the analytical and the numerical solutions, I am kind of double checked everything, still not seeing where the error might come from!!
Torsten
Torsten 2022년 8월 10일
This is the best approximation to your data with a resulting kla value of 389.
I think you will admit that with such swinging data, taking numerical gradients leads to nowhere.
Time = [15.5189990000000 15.5194990000000 15.5199990000000 15.5204990000000 15.5209990000000 15.5214990000000 15.5219990000000 15.5224990000000 15.5229990000000 15.5234990000000 15.5239990000000 15.5244990000000 15.5249990000000 15.5254990000000 15.5259990000000 15.5264990000000 15.5269990000000 15.5274990000000 15.5279990000000 15.5284990000000 15.5289990000000 15.5294990000000 15.5299990000000 15.5304990000000 15.5309990000000 15.5314990000000 15.5319990000000 15.5324990000000 15.5329990000000 15.5334990000000 15.5339990000000 15.5344990000000 15.5349990000000 15.5354990000000 15.5359990000000 15.5364990000000 15.5369990000000 15.5374990000000 15.5379990000000 15.5384990000000 15.5389990000000 15.5394990000000 15.5399990000000 15.5404990000000 15.5409990000000 15.5414990000000 15.5419990000000];
DOT = [86.2934346288157 88.3330265127609 88.5384902983721 86.2715655041141 86.2499514074551 87.9439995156669 93.3559053355719 100.588355429879 105.134156185296 105.998293130410 101.914607317850 97.2442257193124 96.1705619186325 97.6457751783728 102.639322947358 106.338201652074 103.282744164835 99.3874791803122 98.3360407005509 98.1827495464303 98.4462091917985 98.4677691127529 98.6027332770350 99.3776569743805 101.164673911659 102.507302979436 101.756315732742 100.862114099507 100.796601964307 100.746832837656 100.715064263002 100.703558708876 100.714578643816 100.750386536354 100.813244855022 100.905416068358 101.029162644892 101.186747053159 101.341304721314 101.205048020864 100.712709159760 100.334695799161 100.192106610432 100.121980159814 100.129391137103 100.219415163613 100.329039499815];
DOT_star = 100;
fun = @(kla) DOT - DOT_star - (DOT(1) - DOT_star).*exp(-kla*(Time-Time(1)));
kla = lsqnonlin(fun,1)
Local minimum possible. lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
kla = 388.7042
plot(Time,DOT)
hold on
plot(Time,DOT_star + (DOT(1) - DOT_star).*exp(-kla*(Time-Time(1))))

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

답변 (1개)

Torsten
Torsten 2022년 8월 8일
편집: Torsten 2022년 8월 9일
If your results from the theoretical equation for K_la and from the numerical formula don't correspond, it's indicating that the mass transfer law
du/dt = K_la * (u* - u)
doesn't apply for your data.
Note that usually the formula
kla = (gradient(DOT) ) ./ (gradient(Time) .* (DOT_star - DOT));
shouldn't work at all because gradient(DOT) and DOT don't have the same number of elements.
  댓글 수: 1
Sami
Sami 2022년 8월 9일
actually, in this case both does, gradient gives the ame vector length of DOT

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

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by