lsqnonlin data plotting and verification

6 ビュー (過去 30 日間)
형진 김
형진 김 2022 年 3 月 31 日
編集済み: Matt J 2022 年 3 月 31 日
Hello, I've been spending a lot of time with my data lately.
To optimize Fick's second low and my data, I made an objective function and ran it, and the data value was calculated, but I wasn't sure if it worked correctly.
I am attaching the function I wrote.
function equation = myobjective(D_in)
c_m = zeros(6,1);
c_m(1,1) = 0.47683;
c_m(2,1) = 0.00108063;
c_m(3,1) = 0.00005262;
c_m(4,1) = 0.00000709;
c_m(5,1) = 0.00000158;
c_m(6,1) = 0.00000047;
q_m = zeros(6,1);
q_m(1,1) = 2.79224;
q_m(2,1) = 22.54350400;
q_m(3,1) = 62.07328340;
q_m(4,1) = 121.29189583;
q_m(5,1) = 200.25023496;
q_m(6,1) = 298.94340840;
t_n = zeros(6,1);
t_n(1,1) = 900;
t_n(2,1) = 1800;
t_n(3,1) = 3600;
t_n(4,1) = 5400;
t_n(5,1) = 7200;
t_n(6,1) = 10800;
X_exp = zeros(6,1);
X_exp(1,1) = 0.3640;
X_exp(2,1) = 0.3048;
X_exp(3,1) = 0.1785;
X_exp(4,1) = 0.1230;
X_exp(5,1) = 0.0736;
X_exp(6,1) = 0.0595;
a = 0.01;
equation = zeros(6,1);
x_comp = zeros(6,1);
for n=1:6
for m=1:6
x_comp(1,1) = c_m(m,1)*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
x_comp(2,1) = x_comp(2,1) + c_m(m,1).^3*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
x_comp(3,1) = x_comp(3,1) + c_m(m,1).^3*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
x_comp(4,1) = x_comp(4,1) + c_m(m,1).^3*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
x_comp(5,1) = x_comp(5,1) + c_m(m,1).^3*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
x_comp(6,1) = x_comp(6,1) + c_m(m,1).^3*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
end
equation(n,1) = X_exp(n,1) - x_comp(n,1);
end
end
options = optimoptions(@lsqnonlin,'Algorithm', 'trust-region-reflective','Display', 'iter', 'MaxFunctionEvaluations', 1000000, 'MaxIterations', 100000);
D_in = zeros(1,1);
lower_bound = 10^(-10);
upper_bound = 10^(-8);
output_with_bound = lsqnonlin(@myobjective, D_in, lower_bound, upper_bound, options)
output_without_bound = lsqnonlin(@myobjective, D_in,[], [], options)
There are two things I want to ask you.
1. Is there a way to verify that my results were calculated correctly?
(in graph form if possible)
2. Can I plot D_in and T_n in my function result?
I've spent a lot of time trying to study MATLAB, but I still don't know much. I hope you all can help.
+ I use an English translator, so there may be some awkwardness in the text. Sorry in advance.
thank you.

回答 (1 件)

Matt J
Matt J 2022 年 3 月 31 日
編集済み: Matt J 2022 年 3 月 31 日
If you use lsqcurvefit instead of lsqnonlin, any of the examples here,
will show you how to do what you want. However, one problem I see already is in the code below. It appears that x_comp(2:6) are identical to one another, so it is unlikely that the result will match X_exp(2:6), which are not identical.
x_comp(1,1) = c_m(m,1)*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
x_comp(2,1) = x_comp(2,1) + c_m(m,1).^3*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
x_comp(3,1) = x_comp(3,1) + c_m(m,1).^3*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
x_comp(4,1) = x_comp(4,1) + c_m(m,1).^3*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
x_comp(5,1) = x_comp(5,1) + c_m(m,1).^3*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);
x_comp(6,1) = x_comp(6,1) + c_m(m,1).^3*exp(-D_in*t_n(n,1)*q_m(m,1)*3*10000);

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by