How can I use fmisearch() to evaluate the parameters in a matrix?
1 view (last 30 days)
Show older comments
I have the following equation:
f(t)=integral(g(t,x)*h(x) dx)
I discretized the problems because the symbolic expression can't be evaluate (too complicated), so:
where:
f(t) is a vector length=n;
g(t,x) is a matrix n rows and m columns;
h(x) should be a vector length=m. However it depends on 3 parameters.
I want to determine those 3 parameters such that f(t)-integral()=0.
If the 3 parameters are known I use trapz or Simpson method to evaluate the integral.
Do you know a method to apply fminsearch() to evaluate the 3 parameters?
Thank you in advance
0 Comments
Accepted Answer
Star Strider
on 30 Apr 2021
If the objective is to determine the parameter at a zero-crossing (root), use fsolve or fzero, not fminsearch.
Try something like this —
g = @(t,x) sin(2*pi*x.*t); % Create Function
h = @(x) exp(x); % Create Function
a = -5; % Define Lower Integration Limit
b = +5; % Define Upper Integration Limit
f = @(t) integral(@(x)g(t,x).*h(x), a, b) % Integral Funciton Call (Objective Fucntion)
[T,Fval] = fsolve(f, 42) % Estimate Parameter
.
9 Comments
Star Strider
on 1 May 2021
As always, my pleasure!
Even with the revisions, I cannot get it to even come remotely close to fitting ‘G’. If the code is correct, there could be a problems with the constant values or magnitudes.
For the record, the current code is —
G0N=2E5;
Me=18500;
M_star=160000;
k_tdd=1.05E-15;
k_rouse=2E-12;
beta=2.3;
% syms I t mw M0 a b
digits(5)
x = @(t,mw) t./(M_star*k_tdd*(mw.^2));
gx = @(t,mw) -x(t,mw)+sqrt(x(t,mw)).*sqrt(x(t,mw)+(sqrt(pi*x(t,mw)))+pi);
U = @(t,mw) ((1./k_tdd).*(1./(mw.^3)).*t)+(M_star.*gx(t,mw)./mw);
F_sr = @(t,mw) (8/pi^2)*integral(@(I) 1./((2*I-1).^2) .* exp(-(2*I-1).^2 .* U(t,mw)), 1, inf, 'ArrayValued',1);
wGEX = @(mw,M0,a,b) 1.9*(((mw./M0).^(a+1)).*exp(-(mw/M0).^b));
w = @(mw,M0,a,b) wGEX(mw,M0,a,b)./mw;
F_w = @(t,mw,M0,a,b) F_sr(t,mw).*w(mw,M0,a,b);
G = @(t,M0,a,b) integral(@(mw)F_w(t,mw,M0,a,b), 0, inf, 'ArrayValued',1);
G_fcn = @(t,M0,a,b) G0N.*(G(t,M0,a,b)).^beta;
t = [100 50 25 10 5 2.63 1.03 0.526 0.244 0.0991 0.0516 0.0251 0.00996 0.00495 0.00252 0.001 ];
G = [124 879 6110 31900 64000 94400 131000 151000 169000 184000 193000 201000 209000 215000 235000 303000 ];
G_fcnp = @(p,t) G_fcn(t,p(1),p(2),p(3));
ObjFcn = @(p) norm(G - G_fcnp(p,t))
% n_exp = numel(t);
% ObjFcn = @(p) (1./n_exp).*sum(((G -G_fcnp(p,t)).^2)./(G.^2));
P0=[10 3 200000];
ms = MultiStart;
problem = createOptimProblem('fmincon', 'x0',P0, 'objective',ObjFcn);
P = run(ms,problem,250)
% [P,resnorm] = lsqcurvefit(G_fcnp, randn(3,1), t, G)
G_out = G_fcnp(P,t)
figure
plot(t, G, 'p')
hold on
plot(t, G_fcnp(P,t), '-r')
hold off
grid
The estimates for the parameters are —
P =
336.9743 48.8744 369.3595
It does not converge to a successful result with either version of ‘ObjFcn’.
More Answers (1)
3Nz0
on 1 May 2021
8 Comments
Star Strider
on 1 May 2021
Thank you!
I’ll check those. If I can improve on them, I’ll post back here.
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!